package com.xinchuang.service.impl;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xinchuang.comment.KeyWord;
import com.xinchuang.comment.R;
import com.xinchuang.domain.entity.TestModelParam;
import com.xinchuang.domain.pojo.TryOutDeviceMod;
import com.xinchuang.domain.type.*;
import com.xinchuang.domain.vo.byd.*;
import com.xinchuang.domain.vo.df.*;
import com.xinchuang.domain.vo.inner.*;
import com.xinchuang.domain.vo.inner.AssemblyFee;
import com.xinchuang.domain.vo.jl.*;
import com.xinchuang.domain.vo.out.*;
import com.xinchuang.domain.vo.out.DesignFee;
import com.xinchuang.domain.vo.out.OtherFee;
import com.xinchuang.domain.vo.out.req.NormalOutQuotationDetailReqVo;
import com.xinchuang.domain.vo.out.req.NormalOutQuotationReqVo;
import com.xinchuang.domain.vo.out.req.NormalOutQuotationaSubDetailReqVo;
import com.xinchuang.domain.vo.out.res.NormalOutQuotationDetailResVo;
import com.xinchuang.domain.vo.out.res.NormalOutQuotationResVo;
import com.xinchuang.domain.vo.out.res.NormalOutQuotationaSubDetailResVo;
import com.xinchuang.domain.vo.qr.*;
import com.xinchuang.domain.vo.qr.ManufacturingFee;
import com.xinchuang.entity.*;
import com.xinchuang.entity.api.InnerQuotationApi;
import com.xinchuang.manager.TestModelParamService;
import com.xinchuang.mapper.*;
import com.xinchuang.service.*;
import com.xinchuang.service.actual.TryOutDeviceModService;
import com.xinchuang.service.apiutil.impl.ApiUtilServiceImpl;
import com.xinchuang.utils.BigdecimalUtil;
import com.xinchuang.utils.IdUtils;
import com.xinchuang.utils.MyUtils;
import com.xinchuang.utils.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.time.LocalDate;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Service
public class QuotationModServiceImpl implements QuotationModService {

    /**
     * 模具表service
     */
    @Autowired
    private TestModelParamService testModelParamService;
    /**
     * 内部报价service
     */
    @Autowired
    private IInnerQuotationService innerQuotationService;
    /**
     * 内部报价详情service
     */
    @Autowired
    private IInnerQuotationDetailService iInnerQuotationDetailService;
    /**
     * 内部报价价格表Service接口
     */
    @Autowired
    private IInnerQuotationPartPriceService iInnerQuotationPartPriceService;
    @Autowired
    private IPartPriceService partPriceService;
    @Resource
    private MoldTypeModService moldTypeModService;
    @Autowired
    private PartMapper partMapper;
    @Autowired
    private CommonQuotationMapper commonQuotationMapper;
    @Autowired
    private CommonQuotationDetailMapper commonQuotationDetailMapper;
    @Autowired
    private ICommonQuotationDetailService commonQuotationDetailService;
    @Autowired
    private ICommonQuotationPriceService commonQuotationPriceService;
    @Autowired
    private CommonQuotationPriceMapper commonQuotationPriceMapper;
    @Autowired
    private TestModelParamMapper testModelParamMapper;
    @Autowired
    private ExportDfOutQuotationServiceImpl exportDfOutQuotationService;
    @Autowired
    private ExportNormalOutQuotationService exportNormalOutQuotationService;
    @Autowired
    private ExportInnerQuotationService exportInnerQuotationService;
    @Autowired
    private ExportBYDOutQuotationService exportBYDOutQuotationService;
    @Autowired
    private ExportQROutQuotationService exportQROutQuotationService;

    @Resource
    private ExportJlOutQuotationService exportJlOutQuotationService;

    @Autowired
    private IDfQuotationService dfQuotationService;
    @Autowired
    private IDfQuotationDetailService dfQuotationDetailService;
    @Autowired
    private IDfQuotationPriceService dfQuotationPriceService;
    @Autowired
    private TryOutDeviceModService tryOutDeviceModService;

    /**
     * 吉利service
     */
    @Resource
    private IJlQuotationService jlQuotationService;
    /**
     * 吉利 priceService
     */
    @Resource
    private IJlQuotationPriceService jlQuotationPriceService;
    /**
     * 吉利 priceService
     */
    @Resource
    private IJlQuotationDetailService jlQuotationDetailService;
    @Autowired
    private IQrQuotationService iQrQuotationService;
    @Autowired
    private IQrQuotationDetailService iQrQuotationDetailService;
    @Autowired
    private IQrQuotationPriceService iQrQuotationPriceService;
    @Autowired
    private IBydQuotationService iBydQuotationService;
    @Autowired
    private IBydQuotationDetailService iBydQuotationDetailService;
    @Autowired
    private IBydQuotationPriceService iBydQuotationPriceService;
    /**
     * 验证报价数据是否准确service
     */
    @Autowired
    private CheckQuotationDataService checkQuotationDataService;

    @Autowired
    private PlatformTransactionManager transactionManager;
    @Autowired
    private KeyWord keyWord;

    @Override
    public String getInnerQuotation(JSONObject jsonObject) {
        ReqInnerQuoDetailsVO resp = null;
        try {
            //jsonobject解析获取选模表Id
            String moldSelectionId = jsonObject.getString("moldSelectionId");
            resp = new ReqInnerQuoDetailsVO();
            resp.setMoldSelectionId(moldSelectionId);
            LambdaQueryWrapper<InnerQuotation> innerQuotationLambdaQueryWrapper = new QueryWrapper<InnerQuotation>()
                    .lambda()
                    .eq(InnerQuotation::getMoldSelectionId, moldSelectionId);
            InnerQuotation one = innerQuotationService.getOne(innerQuotationLambdaQueryWrapper);
            if (null != one) {
                resp.setStatus(one.getStatus());
            } else {
                resp.setStatus("0");
            }
            TotalFee totalFee = assignmentTotalFee(one);
            resp.setTotalFeeOfAll(totalFee);
            // 转换对象
            List<InnerBaseInfo> extracted = Lists.newArrayList();
            // 查询内部报价信息
            List<InnerQuotationDetail> quotationDetails = iInnerQuotationDetailService.list(new LambdaQueryWrapper<InnerQuotationDetail>().eq(InnerQuotationDetail::getMoldSelectionId, moldSelectionId).orderByAsc(InnerQuotationDetail::getMoldId));
            if (CollectionUtils.isEmpty(quotationDetails)) {
                //如果InnerQuotationDetail表为空，则从TestModelParam表取数据进行初始化
                List<TestModelParam> modelParamList = testModelParamService.list(new LambdaQueryWrapper<TestModelParam>().eq(TestModelParam::getMoldSelectionId, moldSelectionId).orderByAsc(TestModelParam::getMoldId));
                //转换
                extracted = convertTestModel(modelParamList);
                resp.setStatus("0");
            } else {
                //转换
                extracted = convertInnerQuotation(quotationDetails);
            }
            resp.setDataList(extracted);
            if (jsonObject == null || jsonObject.size() < 1) {
                return JSON.toJSONString(R.fail("无数据"));
            }
        } catch (RuntimeException e) {
            log.error("获取内部报价单时失败:{}", e.toString(), e);
            return JSON.toJSONString(R.fail(e.getMessage()));
        } catch (Exception e) {
            log.error("获取内部报价单时失败:{}", e.toString(), e);
            return JSON.toJSONString(R.fail("保存失败"));
        }
        return JSON.toJSONString(R.data(resp), SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullListAsEmpty);
    }


    private TotalFee assignmentTotalFee(InnerQuotation quotation) {
        TotalFee totalFee = new TotalFee();
        if (quotation != null) {
            totalFee.setAssemblyfeeTotal(StringUtils.isBlank(quotation.getAssemblyFee()) ? 0.0 : Double.valueOf(quotation.getAssemblyFee()));
            totalFee.setBoughtInComponentsTotal(StringUtils.isBlank(quotation.getBoughtInComponents()) ? 0.0 : Double.valueOf(quotation.getBoughtInComponents()));
            totalFee.setFinalTaxNotIncludedTotal(StringUtils.isBlank(quotation.getPriceWithoutTax()) ? 0.0 : Double.valueOf(quotation.getPriceWithoutTax()));
            totalFee.setHotRunnerAimFeeTotal(StringUtils.isBlank(quotation.getHotRunnerFee()) ? 0.0 : Double.valueOf(quotation.getHotRunnerFee()));
            totalFee.setIronMaterialsFeeTotal(StringUtils.isBlank(quotation.getIronMaterialFee()) ? 0.0 : Double.valueOf(quotation.getIronMaterialFee()));
            totalFee.setMainMaterialsFeeTotal(StringUtils.isBlank(quotation.getMainMaterialFee()) ? 0.0 : Double.valueOf(quotation.getMainMaterialFee()));
            totalFee.setManufacturingFeeTotal(StringUtils.isBlank(quotation.getManufacturingFee()) ? 0.0 : Double.valueOf(quotation.getManufacturingFee()));
            totalFee.setMouldFeeTotal(StringUtils.isBlank(quotation.getMouldFee()) ? 0.0 : Double.valueOf(quotation.getMouldFee()));
            totalFee.setOutsourceFeeTotal(StringUtils.isBlank(quotation.getOutsourceFee()) ? 0.0 : Double.valueOf(quotation.getOutsourceFee()));
            totalFee.setPercentageOfFinalProcessTargetGrossProfitTotal(quotation.getGrossProfitRatio());
            totalFee.setPeriodRectificationFeeTotal(StringUtils.isBlank(quotation.getPeriodFee()) ? 0.0 : Double.valueOf(quotation.getPeriodFee()));
            totalFee.setPlasticMaterialAimFeeTotal(StringUtils.isBlank(quotation.getPlasticFee()) ? 0.0 : Double.valueOf(quotation.getPlasticFee()));
            totalFee.setStandardComponentFeeTotal(StringUtils.isBlank(quotation.getStandardComponentFee()) ? 0.0 : Double.valueOf(quotation.getStandardComponentFee()));
            totalFee.setTargetGrossProfitTotal(StringUtils.isBlank(quotation.getGrossProfit()) ? 0.0 : Double.valueOf(quotation.getGrossProfit()));
            totalFee.setTexturingAimFeeTotal(StringUtils.isBlank(quotation.getTextureFee()) ? 0.0 : Double.valueOf(quotation.getTextureFee()));
            totalFee.setTransportFeeTotal(StringUtils.isBlank(quotation.getTransportFee()) ? 0.0 : Double.valueOf(quotation.getTransportFee()));
            totalFee.setTryoutFeeTotal(StringUtils.isBlank(quotation.getTryoutFee()) ? 0.0 : Double.valueOf(quotation.getTryoutFee()));
        } else {
            totalFee.setAssemblyfeeTotal(0.0);
            totalFee.setBoughtInComponentsTotal(0.0);
            totalFee.setFinalTaxNotIncludedTotal(0.0);
            totalFee.setHotRunnerAimFeeTotal(0.0);
            totalFee.setIronMaterialsFeeTotal(0.0);
            totalFee.setMainMaterialsFeeTotal(0.0);
            totalFee.setManufacturingFeeTotal(0.0);
            totalFee.setMouldFeeTotal(0.0);
            totalFee.setOutsourceFeeTotal(0.0);
            totalFee.setPercentageOfFinalProcessTargetGrossProfitTotal("");
            totalFee.setPeriodRectificationFeeTotal(0.0);
            totalFee.setPlasticMaterialAimFeeTotal(0.0);
            totalFee.setStandardComponentFeeTotal(0.0);
            totalFee.setTargetGrossProfitTotal(0.0);
            totalFee.setTexturingAimFeeTotal(0.0);
            totalFee.setTransportFeeTotal(0.0);
            totalFee.setTryoutFeeTotal(0.0);
        }
        return totalFee;
    }

    /**
     * 转换方法
     *
     * @param modelParamList
     * @return
     */
    private List<InnerBaseInfo> convertTestModel(List<TestModelParam> modelParamList) {
        return modelParamList.stream()
                .map(source -> {
                    InnerBaseInfo target = new InnerBaseInfo();
                    target.setMoldSelectionId(source.getMoldSelectionId());
                    target.setMoldId(source.getMoldId());
                    target.setImageOfProduct(source.getProductImage());// 图片
                    target.setNameOfProduct(source.getProductName());//产品名称
                    target.setPerCavitiesOfMold(source.getCavityNum()); // 型腔数量(即每模腔数)
                    target.setMaterialOfCavity(source.getCore()); // 模具材质（即型芯材质）
                    target.setHeightOfProduct(StringUtils.isBlank(source.getProductHeight()) ? 0.0 : Double.valueOf(source.getProductHeight())); // 产品尺寸-高
                    target.setWidthOfProduct(StringUtils.isBlank(source.getProductWidth()) ? 0.0 : Double.valueOf(source.getProductWidth())); // 产品尺寸-宽
                    target.setLengthOfProduct(StringUtils.isBlank(source.getProductLength()) ? 0.0 : Double.valueOf(source.getProductLength())); // 产品尺寸-长
                    // 装配费用 (费用详情中装配费用价格)
                    target.setAssemblyFee(0.0f);
                    // 外购件（包含电极和检具）
                    target.setBoughtInComponents(0.0f);
                    // 最终未含税
                    target.setFinalTaxNotIncluded(0.0f);
                    // 热流道目标价
                    target.setHotRunnerAimFee(0.0f);
                    // 热流道品牌
                    target.setHotRunnerBrand("");
                    // 小钢料（费用）
                    target.setIronMaterialsFee(0.0f);
                    // AB板及主材（费用）
                    target.setMainMaterialsFee(0.0f);
                    // 制造费用
                    target.setManufacturingFee(0.0f);
                    //模具类型
                    target.setMoldTypeId(source.getMoldType());
                    // 模架(费用)
                    target.setMouldFee(0.0f);
                    // 外协费+自制费
                    target.setOutsourceFee(0.0f);
                    // 最终工序目标毛利润占比
                    target.setPercentageOfFinalProcessTargetGrossProfit("");
                    // 期间整改费用
                    target.setPeriodRectificationFee(0.0f);
                    // 塑胶材料目标价 (费用详情中塑胶材料价格)
                    target.setPlasticMaterialAimFee(0.0f);
                    // 标准件
                    target.setStandardComponentFee(0.0f);
                    // 分表Id
                    target.setSubTableId(null);
                    // 目标毛利润
                    target.setTargetGrossProfit(0.0f);
                    // 纹理费用目标价 (费用详情中纹理价格)
                    target.setTexturingAimFee(0.0f);
                    // 运输费用 (费用详情中运输费用)
                    target.setTransportFee(0.0f);
                    // 试模费用 (费用详情中试模费用的总费用)
                    target.setTryoutFee(0.0f);
                    // 试模次数
                    target.setTryoutTimes("");
                    //处理detailData 数据
                    DetailData detailData = new DetailData();
                    detailData.setAssemblyFeeOfDetail(new AssemblyFee());
                    detailData.setMouldInfo(new MoldInfo());
                    target.setDetailData(detailData);
                    return target;
                })
                .collect(Collectors.toList());
    }

    private List<InnerBaseInfo> convertInnerQuotation(List<InnerQuotationDetail> modelParamList) {
        return modelParamList.stream()
                .map(source -> {
                    InnerBaseInfo target = new InnerBaseInfo();
                    target.setAssemblyFee(MyUtils.formatDouble(source.getAssemblyFee()));
                    target.setBoughtInComponents(MyUtils.formatDouble(source.getBoughtInComponents()));
                    target.setFinalTaxNotIncluded(MyUtils.formatDouble(source.getPriceWithoutTax()));
                    target.setHeightOfProduct(MyUtils.formatDouble(source.getProductHeight()));
                    target.setHotRunnerAimFee(MyUtils.formatDouble(source.getHotRunnerFee()));
                    target.setHotRunnerBrand(source.getPour());
                    target.setImageOfProduct(source.getProductImage());
                    target.setIronMaterialsFee(MyUtils.formatDouble(source.getIronMaterialFee()));
                    target.setLengthOfProduct(MyUtils.formatDouble(source.getProductLength()));
                    target.setMainMaterialsFee(MyUtils.formatDouble(source.getMainMaterialFee()));
                    target.setManufacturingFee(MyUtils.formatDouble(source.getManufacturingFee()));
                    target.setMaterialOfCavity(source.getCore());
                    target.setMoldId(source.getMoldId());
                    target.setMoldSelectionId(source.getMoldSelectionId());
                    target.setMoldTypeId(source.getMoldTypeId());
                    target.setMouldFee(MyUtils.formatDouble(source.getMouldFee()));
                    target.setNameOfProduct(source.getProductName());
                    target.setOutsourceFee(MyUtils.formatDouble(source.getOutsourceFee()));
                    target.setPerCavitiesOfMold(source.getCavityNum());
                    target.setPercentageOfFinalProcessTargetGrossProfit(source.getGrossProfitRatio());
                    target.setPeriodRectificationFee(MyUtils.formatDouble(source.getPeriodFee()));
                    target.setPlasticMaterialAimFee(MyUtils.formatDouble(source.getPlasticFee()));
                    target.setStandardComponentFee(MyUtils.formatDouble(source.getStandardComponentFee()));
                    target.setSubTableId(source.getId());
                    target.setTargetGrossProfit(MyUtils.formatDouble(source.getGrossProfit()));
                    target.setTexturingAimFee(MyUtils.formatDouble(source.getTextureFee()));
                    target.setTransportFee(MyUtils.formatDouble(source.getTransportFee()));
                    target.setTryoutFee(MyUtils.formatDouble(source.getTryoutFee()));
                    target.setTryoutTimes(source.getTryoutTimes());
                    target.setWidthOfProduct(MyUtils.formatDouble(source.getProductWidth()));

                    //处理detailData 数据
                    DetailData detailData = new DetailData();
                    //处理零件及其他数据
                    getPartAndotherData(source.getMoldId(), detailData);
                    //处理小刚料
                    getInnerQuoIronMaterialList(source.getMoldId(), detailData);


                    //零件所属模具类型（保险杠大型模具）
                    detailData.setMoldTypeId(source.getMoldTypeId());
                    //产品尺寸-高
                    detailData.setHeightOfProduct(StringUtils.isBlank(source.getProductHeight()) ? 0.0 : Double.valueOf(source.getProductHeight()));
                    //产品尺寸-长
                    detailData.setLengthOfProduct(StringUtils.isBlank(source.getProductLength()) ? 0.0 : Double.valueOf(source.getProductLength()));
                    //产品尺寸-宽
                    detailData.setWidthOfProduct(StringUtils.isBlank(source.getProductWidth()) ? 0.0 : Double.valueOf(source.getProductWidth()));


                    target.setDetailData(detailData);
                    return target;
                })
                .collect(Collectors.toList());
    }

    /**
     * 根据摸具id获取 零件明细 和 其他数据（除小刚料）
     *
     * @param moldId
     * @param detailData
     */
    private void getPartAndotherData(String moldId, DetailData detailData) {
        AssemblyFee assemblyFee = new AssemblyFee();
        HotRunner hotRunner = new HotRunner();
        OilCylinder oilCylinder = new OilCylinder();
        PlasticMaterialCost plasticMaterialCost = new PlasticMaterialCost();
        TexturingCost texturingCost = new TexturingCost();
        TryoutFee tryoutFeeOfDetail = new TryoutFee();
        MoldInfo mouldInfo = new MoldInfo();

        List<MoldPart> moldPartList = Lists.newArrayList();
        List<PartPrice> partPrices = partPriceService.list(new LambdaQueryWrapper<PartPrice>().eq(PartPrice::getMoldId, moldId).orderByAsc(PartPrice::getPartName));
        for (PartPrice partPrice : partPrices) {
            String partName = partPrice.getPartName();
            String price = partPrice.getPrice();
            String num = partPrice.getNum();
            String totalPrice = partPrice.getTotalPrice();
            //类型（1：零件明细；2：其他数据；）
            if ("1".equals(partPrice.getType())) {
                MoldPart moldPart = new MoldPart();
                moldPart.setId(partPrice.getId());
                moldPart.setPartId(partPrice.getPartId());
                moldPart.setPartName(partName);
                moldPart.setLengthOfPart(MyUtils.formatDouble(partPrice.getLength()));
                moldPart.setWidthOfPart(MyUtils.formatDouble(partPrice.getWidth()));
                moldPart.setHeightOfPart(MyUtils.formatDouble(partPrice.getHeight()));
                moldPart.setDensityOfPart(MyUtils.formatDouble(partPrice.getDensity()));
                moldPart.setWeightOfPart(MyUtils.formatDouble(partPrice.getWeight()));
                moldPart.setCountOfPart(StringUtils.isBlank(num) ? 0 : Integer.valueOf(num));
                moldPart.setPriceOfPart(MyUtils.formatDouble(price));
                moldPart.setTotalPrice(MyUtils.formatDouble(totalPrice));
                moldPart.setManufacturingFee(MyUtils.formatDouble(partPrice.getCosts()));
                moldPart.setTotalStandardComponentCost(MyUtils.formatDouble(partPrice.getStandardComponentFee()));
                moldPart.setIsMoldFrame(partPrice.getIsMoldFrame());
                moldPart.setIsMainMaterial(partPrice.getIsMainMaterial());
                moldPart.setIsStandardCom(partPrice.getIsStandardCom());
                moldPart.setIsRequired(partPrice.getIsRequired());
                moldPartList.add(moldPart);
            }
            if ("2".equals(partPrice.getType())) {
                //装配费用
                if (InnerOtherEnum.ONE.getName().equals(partPrice.getPartName())) {
                    assemblyFee.setNum(StringUtils.isBlank(partPrice.getNum()) ? 0 : Integer.valueOf(partPrice.getNum()));
                    assemblyFee.setPrice(MyUtils.formatDouble(partPrice.getPrice()));
                    assemblyFee.setTotalPrice(MyUtils.formatDouble(partPrice.getTotalPrice()));
                }
                //热流道
                if (InnerOtherEnum.TWO.getName().equals(partPrice.getPartName())) {
                    hotRunner.setNum(StringUtils.isBlank(partPrice.getNum()) ? 0 : Integer.valueOf(partPrice.getNum()));
                    hotRunner.setPrice(MyUtils.formatDouble(partPrice.getPrice()));
                    hotRunner.setTotalPrice(MyUtils.formatDouble(partPrice.getTotalPrice()));
                }
                //油缸
                if (InnerOtherEnum.THREE.getName().equals(partPrice.getPartName())) {
                    oilCylinder.setNum(StringUtils.isBlank(partPrice.getNum()) ? 0 : Integer.valueOf(partPrice.getNum()));
                    oilCylinder.setPrice(MyUtils.formatDouble(partPrice.getPrice()));
                    oilCylinder.setTotalPrice(MyUtils.formatDouble(partPrice.getTotalPrice()));
                }
                //塑料材料
                if (InnerOtherEnum.FOUR.getName().equals(partPrice.getPartName())) {
                    plasticMaterialCost.setWeight(MyUtils.formatDouble(partPrice.getWeight()));
                    plasticMaterialCost.setPrice(MyUtils.formatDouble(partPrice.getPrice()));
                    plasticMaterialCost.setTotalPrice(MyUtils.formatDouble(partPrice.getTotalPrice()));
                }
                //纹理价格
                if (InnerOtherEnum.FIVE.getName().equals(partPrice.getPartName())) {
                    texturingCost.setArea(MyUtils.formatDouble(partPrice.getNum()));
                    texturingCost.setPrice(MyUtils.formatDouble(partPrice.getPrice()));
                    texturingCost.setTotalPrice(MyUtils.formatDouble(partPrice.getTotalPrice()));
                }
                //试模费用
                if (InnerOtherEnum.SIX.getName().equals(partPrice.getPartName())) {
                    tryoutFeeOfDetail.setDeviceId(partPrice.getPartId());
                    tryoutFeeOfDetail.setHour(StringUtils.isBlank(partPrice.getNum()) ? 0 : Integer.valueOf(partPrice.getNum()));
                    tryoutFeeOfDetail.setPrice(MyUtils.formatDouble(partPrice.getPrice()));
                    tryoutFeeOfDetail.setTotalPrice(MyUtils.formatDouble(partPrice.getTotalPrice()));
                }
                //水电油接头，顶针
                if (InnerOtherEnum.SEVEN.getName().equals(partPrice.getPartName())) {
                    detailData.setThimblePrice(MyUtils.formatDouble(partPrice.getStandardComponentFee()));
                }
                //检具
                if (InnerOtherEnum.EIGHT.getName().equals(partPrice.getPartName())) {
                    detailData.setGagePrice(MyUtils.formatDouble(partPrice.getTotalPrice()));
                }
                //石墨电极
                if (InnerOtherEnum.NINE.getName().equals(partPrice.getPartName())) {
                    detailData.setGraphiteElectrodeCost(MyUtils.formatDouble(partPrice.getTotalPrice()));
                }
                //运输费用
                if (InnerOtherEnum.ELEVEN.getName().equals(partPrice.getPartName())) {
                    detailData.setTransportFeeOfDetail(MyUtils.formatDouble(partPrice.getTotalPrice()));
                }
            }
            if ("3".equals(partPrice.getType())) {
                //模架
                if (InnerOtherEnum.TEN.getName().equals(partPrice.getPartName())) {
                    mouldInfo.setCount(MyUtils.formatDouble(partPrice.getNum()));
                    mouldInfo.setHeightOfMould(MyUtils.formatDouble(partPrice.getHeight()));
                    mouldInfo.setLengthOfMould(MyUtils.formatDouble(partPrice.getLength()));
                    mouldInfo.setPrice(MyUtils.formatDouble(partPrice.getPrice()));
                    mouldInfo.setTotalPrice(MyUtils.formatDouble(partPrice.getTotalPrice()));
                    mouldInfo.setWidthOfMould(MyUtils.formatDouble(partPrice.getWidth()));
                    detailData.setMouldInfo(mouldInfo);
                }
            }
        }
        detailData.setAssemblyFeeOfDetail(null == assemblyFee ? new AssemblyFee() : assemblyFee);
        detailData.setHotRunner(null == hotRunner ? new HotRunner() : hotRunner);
        detailData.setOilCylinder(null == oilCylinder ? new OilCylinder() : oilCylinder);
        detailData.setPlasticMaterialCost(null == plasticMaterialCost ? new PlasticMaterialCost() : plasticMaterialCost);
        detailData.setTexturingCost(null == texturingCost ? new TexturingCost() : texturingCost);
        detailData.setTryoutFeeOfDetail(null == tryoutFeeOfDetail ? new TryoutFee() : tryoutFeeOfDetail);
        detailData.setMoldPartList(moldPartList);

    }

    /**
     * 获取小刚料数据
     *
     * @param moldId
     * @param detailData
     * @return
     */
    private void getInnerQuoIronMaterialList(String moldId, DetailData detailData) {
        List<IronMaterial> ironMaterialList = Lists.newArrayList();
        List<InnerQuotationPartPrice> quotationPartPriceList = iInnerQuotationPartPriceService.list(new LambdaQueryWrapper<InnerQuotationPartPrice>().eq(InnerQuotationPartPrice::getMoldId, moldId).orderByAsc(InnerQuotationPartPrice::getName));
        for (InnerQuotationPartPrice quotationPartPrice : quotationPartPriceList) {
            IronMaterial ironMaterial = new IronMaterial();
            ironMaterial.setId(quotationPartPrice.getId());
            ironMaterial.setCount(StringUtils.isBlank(quotationPartPrice.getCount()) ? 0 : Integer.valueOf(quotationPartPrice.getCount()));
            ironMaterial.setIronMaterialsName(quotationPartPrice.getName());
            ironMaterial.setMaterialTotalPrice(MyUtils.formatDouble(quotationPartPrice.getTotalPrice()));
            ironMaterial.setPrice(MyUtils.formatDouble(quotationPartPrice.getPrice()));
            ironMaterial.setProcessPrice(MyUtils.formatDouble(quotationPartPrice.getProcessPrice()));
            ironMaterial.setStandardComponent(MyUtils.formatDouble(quotationPartPrice.getStandardComponentFee()));
            ironMaterial.setTotalProcessPrice(MyUtils.formatDouble(quotationPartPrice.getTotalProcessPrice()));
            ironMaterial.setTotalStandardComponentCost(MyUtils.formatDouble(quotationPartPrice.getTotalStandardComponentFee()));
            ironMaterialList.add(ironMaterial);
        }
        detailData.setIronMaterialList(ironMaterialList);
    }

    @Override
    public String exportInnerQuotation(JSONObject jsonObject) {
        //jsonobject解析获取选模表Id
        if (jsonObject == null || jsonObject.size() < 1) {
            return "{\"msg\":\"参数错误\",\"code\":400,\"success\":false}";
        }
        String filePath = exportInnerQuotationService.exportInnerOutQuotation(this.getInnerQuotation(jsonObject));
        return JSON.toJSONString(R.data("filePath: " + filePath, "导出成功"));
    }

    @Override
    public String getNormalOutQuotation(JSONObject jsonObject) {
        if (jsonObject == null || jsonObject.size() < 1) {
            return JSON.toJSONString(R.fail("参数错误"));
        }
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");

        NormalOutQuotationResVo normalOutQuotationResVo = new NormalOutQuotationResVo();
        //查询通用报价单信息
        LambdaQueryWrapper<CommonQuotation> commonQuotationQueryWrapper = new QueryWrapper<CommonQuotation>()
                .lambda()
                .eq(CommonQuotation::getMoldSelectionId, moldSelectionId);
        CommonQuotation commonQuotation = commonQuotationMapper.selectOne(commonQuotationQueryWrapper);

        //当commonQuotation为空时 根据模具表初始化数据
        if (Objects.isNull(commonQuotation)) {
            LambdaQueryWrapper<TestModelParam> testModelParamLambdaQueryWrapper = new QueryWrapper<TestModelParam>()
                    .lambda()
                    .eq(TestModelParam::getMoldSelectionId, moldSelectionId)
                    .orderByAsc(TestModelParam::getMoldId);
            List<TestModelParam> testModelParamList = testModelParamMapper.selectList(testModelParamLambdaQueryWrapper);
            if (Objects.nonNull(testModelParamList) && !testModelParamList.isEmpty()) {
                //初始化通用外部报价表
                CommonQuotation cq = new CommonQuotation();
                cq.setId(IdUtils.simpleUUID());
                cq.setMoldSelectionId(moldSelectionId);
                commonQuotationMapper.insert(cq);
                for (TestModelParam testModelParam : testModelParamList) {
                    commonQuotation = cq;
                    //初始化通用外部详情表
                    CommonQuotationDetail cqd = new CommonQuotationDetail();
                    BeanUtils.copyProperties(testModelParam, cqd);
                    cqd.setId(IdUtils.simpleUUID());
                    cqd.setCommonQuotationId(cq.getId());
                    cqd.setMachiningMaterialCost("0");
                    cqd.setHeatTreatment("0");
                    cqd.setAssemlyMaterialCost("0");
                    cqd.setDesignCost("0");
                    cqd.setManufacturingCost("0");
                    cqd.setCmmMeasure("0");
                    cqd.setOtherFee("0");

                    commonQuotationDetailMapper.insert(cqd);
                    //初始化通用外部分表数据
                    List<CommonQuotationPrice> commonQuotationPriceList = Arrays.stream(NormalOutQuotationaPriceEnum.values()).map(normalOutQuotationaPriceEnum -> {
                        CommonQuotationPrice commonQuotationPrice = new CommonQuotationPrice();
                        commonQuotationPrice.setId(IdUtils.simpleUUID());
                        commonQuotationPrice.setDetailId(cqd.getId());
                        commonQuotationPrice.setMoldSelectionId(moldSelectionId);
                        commonQuotationPrice.setType(normalOutQuotationaPriceEnum.getType());
                        commonQuotationPrice.setName(normalOutQuotationaPriceEnum.getItemName());
                        commonQuotationPrice.setPrice("0");
                        commonQuotationPrice.setLength("0");
                        commonQuotationPrice.setWidth("0");
                        commonQuotationPrice.setHeight("0");
                        commonQuotationPrice.setNum("0");
                        commonQuotationPrice.setTotalPrice("0");
                        return commonQuotationPrice;
                    }).collect(Collectors.toList());
                    commonQuotationPriceService.saveBatch(commonQuotationPriceList);
                }

            }
        }

        if (Objects.nonNull(commonQuotation)) {
            BeanUtils.copyProperties(commonQuotation, normalOutQuotationResVo);
            //处理特殊字段（大小写，字段重命名问题）
            normalOutQuotationResVo.setEMail(commonQuotation.getEmail());
            normalOutQuotationResVo.setZIP(commonQuotation.getZip());
            normalOutQuotationResVo.setPHONE(commonQuotation.getPhone());
            normalOutQuotationResVo.setTEL(commonQuotation.getTel());
            normalOutQuotationResVo.setPriceWithoutTaxIncludesSkinGrainTotal(
                    new BigDecimal(StringUtils.isBlank(commonQuotation.getPriceWithoutTax()) ? "0" : commonQuotation.getPriceWithoutTax()));
            normalOutQuotationResVo.setCheckoutName(commonQuotation.getAuditor());
            normalOutQuotationResVo.setSkinGrainFeeTotal(
                    new BigDecimal(StringUtils.isBlank(commonQuotation.getTextureFee()) ? "0" : commonQuotation.getTextureFee()));
            normalOutQuotationResVo.setMouldFeeTotal(
                    new BigDecimal(StringUtils.isBlank(commonQuotation.getMoldFee()) ? "0" : commonQuotation.getMoldFee()));
            normalOutQuotationResVo.setQuotedPrice(commonQuotation.getMaker());
            normalOutQuotationResVo.setCheckoutName(commonQuotation.getAuditor());
            normalOutQuotationResVo.setParameter1(commonQuotation.getParam1());
            normalOutQuotationResVo.setParameter2(commonQuotation.getParam2());

            //处理通用报价详情逻辑
            LambdaQueryWrapper<CommonQuotationDetail> quotationDetailLambdaQueryWrapper = new QueryWrapper<CommonQuotationDetail>()
                    .lambda()
                    .eq(CommonQuotationDetail::getCommonQuotationId, commonQuotation.getId())
                    .orderByAsc(CommonQuotationDetail::getId);
            List<CommonQuotationDetail> commonQuotationDetailList = commonQuotationDetailMapper.selectList(quotationDetailLambdaQueryWrapper);

            List<NormalOutQuotationDetailResVo> normalOutQuotationDetailResVoList = commonQuotationDetailList.stream().map(commonQuotationDetail -> {
                NormalOutQuotationDetailResVo normalOutQuotationDetailResVo = new NormalOutQuotationDetailResVo();
                normalOutQuotationDetailResVo.setCodeOfProduct(commonQuotationDetail.getProductCode());
                normalOutQuotationDetailResVo.setNameOfProduct(commonQuotationDetail.getProductName());
                normalOutQuotationDetailResVo.setImageOfProduct(commonQuotationDetail.getProductImage());
                normalOutQuotationDetailResVo.setLengthOfProduct(StringUtils.isNoneBlank(commonQuotationDetail.getProductLength()) ? Double.valueOf(commonQuotationDetail.getProductLength()) : 0D);
                normalOutQuotationDetailResVo.setWidthOfProduct(StringUtils.isNoneBlank(commonQuotationDetail.getProductWidth()) ? Double.valueOf(commonQuotationDetail.getProductWidth()) : 0D);
                normalOutQuotationDetailResVo.setHeightOfProduct(StringUtils.isNoneBlank(commonQuotationDetail.getProductHeight()) ? Double.valueOf(commonQuotationDetail.getProductHeight()) : 0D);
                normalOutQuotationDetailResVo.setCavityCount(commonQuotationDetail.getCavityNum());
                normalOutQuotationDetailResVo.setPourSystem(commonQuotationDetail.getPour());
                normalOutQuotationDetailResVo.setMaterialOfCavity(commonQuotationDetail.getCavity());
                normalOutQuotationDetailResVo.setMaterialOfCore(commonQuotationDetail.getCore());
                normalOutQuotationDetailResVo.setMouldIronMaterial(commonQuotationDetail.getMoldBaseMaterial());
                normalOutQuotationDetailResVo.setSkinGrainFee(StringUtils.isNoneBlank(commonQuotationDetail.getTextureFee()) ? Double.valueOf(commonQuotationDetail.getTextureFee()) : 0D);
                normalOutQuotationDetailResVo.setMouldFee(StringUtils.isNoneBlank(commonQuotationDetail.getMoldFee()) ? Double.valueOf(commonQuotationDetail.getMoldFee()) : 0D);
                normalOutQuotationDetailResVo.setTotalPriceWithoutTaxIncludesSkinGrain(StringUtils.isNoneBlank(commonQuotationDetail.getPriceWithoutTax()) ? Double.valueOf(commonQuotationDetail.getPriceWithoutTax()) : 0D);
                normalOutQuotationDetailResVo.setT0Time(commonQuotationDetail.gett0Time());
                normalOutQuotationDetailResVo.setRemark(commonQuotationDetail.getRemark());

                NormalOutQuotationaSubDetailResVo normalOutQuotationaSubDetailResVo = new NormalOutQuotationaSubDetailResVo();
                normalOutQuotationaSubDetailResVo.setT0Time(commonQuotationDetail.gett0Time());
                normalOutQuotationaSubDetailResVo.setCavityCount(commonQuotationDetail.getCavityNum());
                normalOutQuotationaSubDetailResVo.setCodeOfProduct(commonQuotationDetail.getProductCode());
                normalOutQuotationaSubDetailResVo.setContacts(commonQuotationDetail.getContacts());
                normalOutQuotationaSubDetailResVo.setDrawingNo(commonQuotationDetail.getDrawing());
                normalOutQuotationaSubDetailResVo.setPhone(commonQuotationDetail.getPhone());
                normalOutQuotationaSubDetailResVo.setMoldName(commonQuotationDetail.getMoldName());
                normalOutQuotationaSubDetailResVo.setLengthOfProduct(StringUtils.isNoneBlank(commonQuotationDetail.getProductLength()) ? Double.valueOf(commonQuotationDetail.getProductLength()) : 0D);
                normalOutQuotationaSubDetailResVo.setWidthOfProduct(StringUtils.isNoneBlank(commonQuotationDetail.getProductWidth()) ? Double.valueOf(commonQuotationDetail.getProductWidth()) : 0D);
                normalOutQuotationaSubDetailResVo.setHeightOfProduct(StringUtils.isNoneBlank(commonQuotationDetail.getProductHeight()) ? Double.valueOf(commonQuotationDetail.getProductHeight()) : 0D);
                normalOutQuotationaSubDetailResVo.setWeightOfProduct(StringUtils.isNoneBlank(commonQuotationDetail.getProductWeight()) ? Double.valueOf(commonQuotationDetail.getProductWeight()) : 0D);
                normalOutQuotationaSubDetailResVo.setLengthOfShape(StringUtils.isNoneBlank(commonQuotationDetail.getMoldLength()) ? Double.valueOf(commonQuotationDetail.getMoldLength()) : 0D);
                normalOutQuotationaSubDetailResVo.setWidthOfShape(StringUtils.isNoneBlank(commonQuotationDetail.getMoldWidth()) ? Double.valueOf(commonQuotationDetail.getMoldWidth()) : 0D);
                normalOutQuotationaSubDetailResVo.setHeightOfShape(StringUtils.isNoneBlank(commonQuotationDetail.getMoldHeight()) ? Double.valueOf(commonQuotationDetail.getMoldHeight()) : 0D);
                normalOutQuotationaSubDetailResVo.setMoldWeight(StringUtils.isNoneBlank(commonQuotationDetail.getMoldWeight()) ? Double.valueOf(commonQuotationDetail.getMoldWeight()) : 0D);
                normalOutQuotationaSubDetailResVo.setLeadTime(commonQuotationDetail.getLeadTime());
                normalOutQuotationaSubDetailResVo.setLongevity(commonQuotationDetail.getLongevity());
                normalOutQuotationaSubDetailResVo.setPressTon(commonQuotationDetail.getPress());
                normalOutQuotationaSubDetailResVo.setSkinGrainFee(StringUtils.isNoneBlank(commonQuotationDetail.getTextureFee()) ? Double.valueOf(commonQuotationDetail.getTextureFee()) : 0D);
                normalOutQuotationaSubDetailResVo.setMouldFee(StringUtils.isNoneBlank(commonQuotationDetail.getMoldTotalFee()) ? Double.valueOf(commonQuotationDetail.getMoldTotalFee()) : 0D);
                normalOutQuotationaSubDetailResVo.setTotalPrice(StringUtils.isNoneBlank(commonQuotationDetail.getTotalFee()) ? Double.valueOf(commonQuotationDetail.getTotalFee()) : 0D);
                normalOutQuotationaSubDetailResVo.setSupplier(commonQuotationDetail.getSupplier());
                normalOutQuotationaSubDetailResVo.setSignature(commonQuotationDetail.getSignature());
                normalOutQuotationaSubDetailResVo.setStamp(commonQuotationDetail.getStamp());
                normalOutQuotationaSubDetailResVo.setDate(commonQuotationDetail.getDate());

                //查询分表数据
                LambdaQueryWrapper<CommonQuotationPrice> commonQuotationPriceLambdaQueryWrapper = new QueryWrapper<CommonQuotationPrice>()
                        .lambda()
                        .eq(CommonQuotationPrice::getDetailId, commonQuotationDetail.getId())
                        .orderByAsc(CommonQuotationPrice::getId);
                List<CommonQuotationPrice> commonQuotationPriceList = commonQuotationPriceMapper.selectList(commonQuotationPriceLambdaQueryWrapper);
                Map<String, List<CommonQuotationPrice>> subMap = commonQuotationPriceList.stream().collect(Collectors.groupingBy(CommonQuotationPrice::getType, LinkedHashMap::new, Collectors.toList()));
                subMap.forEach((itemName, list) -> {
                    if (itemName.equals(NormalOutQuotationaSubEnum.MACHINING_MATERIAL_COST.getCn())) {
                        MachiningMaterialCost machiningMaterialCost = new MachiningMaterialCost();
                        List<MachiningMaterialCost.DataList> collect = list.stream().map(commonQuotationPrice ->
                                new MachiningMaterialCost().new DataList(commonQuotationPrice.getId(), commonQuotationPrice.getName(),
                                        Double.valueOf(commonQuotationPrice.getLength()), Double.valueOf(commonQuotationPrice.getWidth()),
                                        Double.valueOf(commonQuotationPrice.getHeight()), Double.valueOf(commonQuotationPrice.getNum()),
                                        Double.valueOf(commonQuotationPrice.getPrice()), Double.valueOf(commonQuotationPrice.getTotalPrice()),
                                        commonQuotationPrice.getSpecification())
                        ).collect(Collectors.toList());
                        machiningMaterialCost.setDataList(collect);
                        machiningMaterialCost.setSubTotal(Double.valueOf(commonQuotationDetail.getMachiningMaterialCost()));

                        normalOutQuotationaSubDetailResVo.setMachiningMaterialCost(machiningMaterialCost);
                    } else if (itemName.equals(NormalOutQuotationaSubEnum.CMM_MEASURE.getCn())) {
                        Cmmmeasure cmmmeasure = new Cmmmeasure();
                        List<Cmmmeasure.DataList> collect = list.stream().map(commonQuotationPrice ->
                                new Cmmmeasure().new DataList(commonQuotationPrice.getId(), commonQuotationPrice.getName(),
                                        Double.valueOf(commonQuotationPrice.getNum()), Double.valueOf(commonQuotationPrice.getPrice()),
                                        Double.valueOf(commonQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        cmmmeasure.setDataList(collect);
                        cmmmeasure.setSubTotal(Double.valueOf(commonQuotationDetail.getCmmMeasure()));

                        normalOutQuotationaSubDetailResVo.setCmmmeasure(cmmmeasure);
                    } else if (itemName.equals(NormalOutQuotationaSubEnum.MANUFACTURING_COST.getCn())) {
                        ManufacturingCost manufacturingCost = new ManufacturingCost();
                        List<ManufacturingCost.DataList> collect = list.stream().map(commonQuotationPrice ->
                                new ManufacturingCost().new DataList(commonQuotationPrice.getId(), commonQuotationPrice.getName(),
                                        Double.valueOf(commonQuotationPrice.getNum()), Double.valueOf(commonQuotationPrice.getPrice()),
                                        Double.valueOf(commonQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        manufacturingCost.setDataList(collect);
                        manufacturingCost.setSubTotal(Double.valueOf(commonQuotationDetail.getManufacturingCost()));

                        normalOutQuotationaSubDetailResVo.setManufacturingCost(manufacturingCost);
                    } else if (itemName.equals(NormalOutQuotationaSubEnum.DESIGN_FEE.getCn())) {
                        DesignFee designFee = new DesignFee();
                        List<DesignFee.DataList> collect = list.stream().map(commonQuotationPrice ->
                                new DesignFee().new DataList(commonQuotationPrice.getId(), commonQuotationPrice.getName(),
                                        Double.valueOf(commonQuotationPrice.getNum()), Double.valueOf(commonQuotationPrice.getPrice()),
                                        Double.valueOf(commonQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        designFee.setDataList(collect);
                        designFee.setSubTotal(Double.valueOf(commonQuotationDetail.getDesignCost()));

                        normalOutQuotationaSubDetailResVo.setDesignFee(designFee);
                    } else if (itemName.equals(NormalOutQuotationaSubEnum.OTHER_FEE.getCn())) {
                        OtherFee otherFee = new OtherFee();
                        List<OtherFee.DataList> collect = list.stream().map(commonQuotationPrice ->
                                new OtherFee().new DataList(commonQuotationPrice.getId(), commonQuotationPrice.getName(),
                                        commonQuotationPrice.getNum(), Double.valueOf(commonQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        otherFee.setDataList(collect);
                        otherFee.setSubTotal(Double.valueOf(commonQuotationDetail.getOtherFee()));

                        normalOutQuotationaSubDetailResVo.setOtherFee(otherFee);
                    } else if (itemName.equals(NormalOutQuotationaSubEnum.ASSEMLY_MATERIAL_COST.getCn())) {
                        AssemlyMaterialCost assemlyMaterialCost = new AssemlyMaterialCost();
                        List<AssemlyMaterialCost.DataList> collect = list.stream().map(commonQuotationPrice ->
                                new AssemlyMaterialCost().new DataList(commonQuotationPrice.getId(), commonQuotationPrice.getName(),
                                        commonQuotationPrice.getSupplier(), Integer.valueOf(commonQuotationPrice.getNum()),
                                        Double.valueOf(commonQuotationPrice.getPrice()), Double.valueOf(commonQuotationPrice.getTotalPrice()),
                                        commonQuotationPrice.getSpecification())
                        ).collect(Collectors.toList());
                        assemlyMaterialCost.setDataList(collect);
                        assemlyMaterialCost.setSubTotal(Double.valueOf(commonQuotationDetail.getAssemlyMaterialCost()));

                        normalOutQuotationaSubDetailResVo.setAssemlyMaterialCost(assemlyMaterialCost);
                    } else if (itemName.equals(NormalOutQuotationaSubEnum.HEAT_TREATMENT.getCn())) {
                        HeatTreatmentCost heatTreatmentCost = new HeatTreatmentCost();
                        List<HeatTreatmentCost.DataList> collect = list.stream().map(commonQuotationPrice ->
                                new HeatTreatmentCost().new DataList(commonQuotationPrice.getId(), commonQuotationPrice.getName(),
                                        Double.valueOf(commonQuotationPrice.getNum()), Double.valueOf(commonQuotationPrice.getPrice()),
                                        Double.valueOf(commonQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        heatTreatmentCost.setDataList(collect);
                        heatTreatmentCost.setSubTotal(Double.valueOf(commonQuotationDetail.getHeatTreatment()));

                        normalOutQuotationaSubDetailResVo.setHeatTreatmentCost(heatTreatmentCost);
                    } else {
                        log.error("不支持的分表类型:{}", itemName);
                    }
                });

                normalOutQuotationDetailResVo.setDetailData(normalOutQuotationaSubDetailResVo);

                return normalOutQuotationDetailResVo;
            }).collect(Collectors.toList());

            normalOutQuotationResVo.setDataList(normalOutQuotationDetailResVoList);
        }

        return JSON.toJSONString(R.data(normalOutQuotationResVo), SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullListAsEmpty);
    }

    @Override
    @Transactional
    public String saveNormalOutQuotation(JSONObject jsonObject) {
        try {
            NormalOutQuotationReqVo normalOutQuotationReqVo = JSONObject.parseObject(jsonObject.toJSONString(), NormalOutQuotationReqVo.class);
            //校验数据的合法性
            checkQuotationDataService.checkNormalData(normalOutQuotationReqVo);

            String moldSelectionId = normalOutQuotationReqVo.getMoldSelectionId();
            //删除报价信息
            LambdaQueryWrapper<CommonQuotation> commonQuotationLambdaQueryWrapper = new QueryWrapper<CommonQuotation>()
                    .lambda()
                    .eq(CommonQuotation::getMoldSelectionId, moldSelectionId);
            CommonQuotation commonQuotation = commonQuotationMapper.selectOne(commonQuotationLambdaQueryWrapper);
            if (Objects.nonNull(commonQuotation)) {
                commonQuotationMapper.deleteById(commonQuotation.getId());
                commonQuotationDetailMapper.delete(new QueryWrapper<CommonQuotationDetail>()
                        .lambda().eq(CommonQuotationDetail::getCommonQuotationId, commonQuotation.getId()));
                commonQuotationPriceMapper.delete(new QueryWrapper<CommonQuotationPrice>()
                        .lambda().eq(CommonQuotationPrice::getMoldSelectionId, moldSelectionId));
            }
            //保存通用对外报价逻辑
            CommonQuotation newCommonQuotation = new CommonQuotation();
            BeanUtils.copyProperties(normalOutQuotationReqVo, newCommonQuotation);
            newCommonQuotation.setId(IdUtils.simpleUUID());
            newCommonQuotation.setZip(normalOutQuotationReqVo.getZIP());
            newCommonQuotation.setPhone(normalOutQuotationReqVo.getPHONE());
            newCommonQuotation.setEmail(normalOutQuotationReqVo.getEMail());
            newCommonQuotation.setTel(normalOutQuotationReqVo.getTEL());
            newCommonQuotation.setMaker(String.valueOf(normalOutQuotationReqVo.getQuotedPrice()));
            newCommonQuotation.setAuditor(normalOutQuotationReqVo.getApprover());
            newCommonQuotation.setApprover(normalOutQuotationReqVo.getCheckoutName());
            newCommonQuotation.setTextureFee(BigDecimal.valueOf(normalOutQuotationReqVo.getSkinGrainFeeTotal()).stripTrailingZeros().toPlainString());
            newCommonQuotation.setPriceWithoutTax(BigDecimal.valueOf(normalOutQuotationReqVo.getPriceWithoutTaxIncludesSkinGrainTotal()).stripTrailingZeros().toPlainString());
            newCommonQuotation.setMoldFee(BigDecimal.valueOf(normalOutQuotationReqVo.getMouldFeeTotal()).stripTrailingZeros().toPlainString());
            commonQuotationMapper.insert(newCommonQuotation);

            //保存通用对外报价详情逻辑
            List<NormalOutQuotationDetailReqVo> dataList = normalOutQuotationReqVo.getDataList();
            List<CommonQuotationDetail> commonQuotationDetailList = new ArrayList<>();
            List<CommonQuotationPrice> commonQuotationPriceList = new ArrayList<>();

            dataList.forEach(normalOutQuotationDetailReqVo -> {
                CommonQuotationDetail commonQuotationDetail = new CommonQuotationDetail();
                commonQuotationDetail.setId(IdUtils.simpleUUID());
                commonQuotationDetail.setCommonQuotationId(newCommonQuotation.getId());
                commonQuotationDetail.setProductCode(normalOutQuotationDetailReqVo.getCodeOfProduct());
                commonQuotationDetail.setProductName(normalOutQuotationDetailReqVo.getNameOfcodeOfProduct());
                commonQuotationDetail.setProductImage(normalOutQuotationDetailReqVo.getImageOfcodeOfProduct());
                commonQuotationDetail.setProductLength(BigDecimal.valueOf(normalOutQuotationDetailReqVo.getLengthOfcodeOfProduct()).stripTrailingZeros().toPlainString());
                commonQuotationDetail.setProductWidth(BigDecimal.valueOf(normalOutQuotationDetailReqVo.getWidthOfcodeOfProduct()).stripTrailingZeros().toPlainString());
                commonQuotationDetail.setProductHeight(BigDecimal.valueOf(normalOutQuotationDetailReqVo.getHeightOfcodeOfProduct()).stripTrailingZeros().toPlainString());
                String productSize = Arrays.asList(commonQuotationDetail.getProductLength(), commonQuotationDetail.getProductWidth(), commonQuotationDetail.getProductHeight())
                        .stream().collect(Collectors.joining("*"));
                commonQuotationDetail.setProductSize(productSize);
                commonQuotationDetail.setCavityNum(normalOutQuotationDetailReqVo.getCavityCount());
                commonQuotationDetail.setPour(normalOutQuotationDetailReqVo.getPourSystem());
                commonQuotationDetail.setCavity(normalOutQuotationDetailReqVo.getMaterialOfCavity());
                commonQuotationDetail.setCore(normalOutQuotationDetailReqVo.getMaterialOfCore());
                commonQuotationDetail.setMoldBaseMaterial(normalOutQuotationDetailReqVo.getMouldIronMaterial());
                commonQuotationDetail.setTextureFee(BigDecimal.valueOf(normalOutQuotationDetailReqVo.getSkinGrainFee()).stripTrailingZeros().toPlainString());
                commonQuotationDetail.setMoldFee(BigDecimal.valueOf(normalOutQuotationDetailReqVo.getMouldFee()).stripTrailingZeros().toPlainString());
                commonQuotationDetail.setPriceWithoutTax(BigDecimal.valueOf(normalOutQuotationDetailReqVo.getTotalPriceWithoutTaxIncludesSkinGrain()).stripTrailingZeros().toPlainString());
                commonQuotationDetail.sett0Time(normalOutQuotationDetailReqVo.getT0Time());
                commonQuotationDetail.setRemark(normalOutQuotationDetailReqVo.getRemark());

                NormalOutQuotationaSubDetailReqVo detailData = normalOutQuotationDetailReqVo.getDetailData();
                if (Objects.nonNull(detailData)) {
                    commonQuotationDetail.setContacts(detailData.getContacts());
                    commonQuotationDetail.setPhone(detailData.getPhone());
                    commonQuotationDetail.setMoldName(detailData.getMoldName());
                    commonQuotationDetail.sett1Time(detailData.getT1Time());
                    commonQuotationDetail.setDrawing(detailData.getDrawingNo());
                    commonQuotationDetail.setLeadTime(detailData.getLeadTime());
                    commonQuotationDetail.setProductWeight(BigDecimal.valueOf(detailData.getWeightOfcodeOfProduct()).stripTrailingZeros().toPlainString());
                    commonQuotationDetail.setMoldLength(BigDecimal.valueOf(detailData.getLengthOfShape()).stripTrailingZeros().toPlainString());
                    commonQuotationDetail.setMoldWidth(BigDecimal.valueOf(detailData.getWidthOfShape()).stripTrailingZeros().toPlainString());
                    commonQuotationDetail.setMoldHeight(BigDecimal.valueOf(detailData.getHeightOfShape()).stripTrailingZeros().toPlainString());
                    commonQuotationDetail.setMoldWeight(BigDecimal.valueOf(detailData.getMoldWeight()).stripTrailingZeros().toPlainString());
                    String moldSize = Arrays.asList(commonQuotationDetail.getMoldLength(), commonQuotationDetail.getMoldWidth(), commonQuotationDetail.getMoldHeight())
                            .stream().collect(Collectors.joining("*"));
                    commonQuotationDetail.setMoldSize(moldSize);
                    commonQuotationDetail.setLongevity(detailData.getLongevity());
                    commonQuotationDetail.setPress(detailData.getPressTon());
                    if (Objects.nonNull(detailData.getAssemlyMaterialCost())) {
                        commonQuotationDetail.setMachiningMaterialCost(BigDecimal.valueOf(detailData.getMachiningMaterialCost().getSubTotal()).stripTrailingZeros().toPlainString());
                    }
                    if (Objects.nonNull(detailData.getHeatTreatmentCost())) {
                        commonQuotationDetail.setHeatTreatment(BigDecimal.valueOf(detailData.getHeatTreatmentCost().getSubTotal()).stripTrailingZeros().toPlainString());
                    }
                    if (Objects.nonNull(detailData.getAssemlyMaterialCost())) {
                        commonQuotationDetail.setAssemlyMaterialCost(BigDecimal.valueOf(detailData.getAssemlyMaterialCost().getSubTotal()).stripTrailingZeros().toPlainString());
                    }
                    if (Objects.nonNull(detailData.getDesignFee())) {
                        commonQuotationDetail.setDesignCost(BigDecimal.valueOf(detailData.getDesignFee().getSubTotal()).stripTrailingZeros().toPlainString());
                    }
                    if (Objects.nonNull(detailData.getManufacturingCost())) {
                        commonQuotationDetail.setManufacturingCost(BigDecimal.valueOf(detailData.getManufacturingCost().getSubTotal()).stripTrailingZeros().toPlainString());
                    }
                    if (Objects.nonNull(detailData.getCmmmeasure())) {
                        commonQuotationDetail.setCmmMeasure(BigDecimal.valueOf(detailData.getCmmmeasure().getSubTotal()).stripTrailingZeros().toPlainString());
                    }
                    if (Objects.nonNull(detailData.getOtherFee())) {
                        commonQuotationDetail.setOtherFee(BigDecimal.valueOf(detailData.getOtherFee().getSubTotal()).stripTrailingZeros().toPlainString());
                    }
                    commonQuotationDetail.setMoldTotalFee(BigDecimal.valueOf(detailData.getMouldFee()).stripTrailingZeros().toPlainString());
                    commonQuotationDetail.setTotalFee(BigDecimal.valueOf(detailData.getTotalPrice()).stripTrailingZeros().toPlainString());
                    commonQuotationDetail.setSupplier(detailData.getSupplier());
                    commonQuotationDetail.setSignature(detailData.getSignature());
                    commonQuotationDetail.setSupplier(detailData.getSupplier());
                    commonQuotationDetail.setStamp(detailData.getStamp());
                    commonQuotationDetail.setDate(detailData.getDate());
                    commonQuotationDetailList.add(commonQuotationDetail);

                    //保存通用对外报价分表逻辑
                    MachiningMaterialCost machiningMaterialCost = detailData.getMachiningMaterialCost();
                    if (Objects.nonNull(machiningMaterialCost) && Objects.nonNull(machiningMaterialCost.getDataList())) {
                        List<MachiningMaterialCost.DataList> subDataList = machiningMaterialCost.getDataList();
                        List<CommonQuotationPrice> list = subDataList.stream().map(sub -> {
                            CommonQuotationPrice commonQuotationPrice = new CommonQuotationPrice();
                            commonQuotationPrice.setId(IdUtils.simpleUUID());
                            commonQuotationPrice.setMoldSelectionId(moldSelectionId);
                            commonQuotationPrice.setDetailId(commonQuotationDetail.getId());
                            commonQuotationPrice.setType(NormalOutQuotationaSubEnum.MACHINING_MATERIAL_COST.getCn());
                            commonQuotationPrice.setName(sub.getItemName());
                            commonQuotationPrice.setLength(BigDecimal.valueOf(sub.getLength()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setWidth(BigDecimal.valueOf(sub.getWidth()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setHeight(BigDecimal.valueOf(sub.getHeight()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setNum(BigDecimal.valueOf(sub.getWeight()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setPrice(BigDecimal.valueOf(sub.getPrice()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setTotalPrice(BigDecimal.valueOf(sub.getTotalPrice()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setSpecification(sub.getSpecification());
                            return commonQuotationPrice;
                        }).collect(Collectors.toList());
                        commonQuotationPriceList.addAll(list);
                    }
                    HeatTreatmentCost heatTreatmentCost = detailData.getHeatTreatmentCost();
                    if (Objects.nonNull(heatTreatmentCost) && Objects.nonNull(heatTreatmentCost.getDataList())) {
                        List<HeatTreatmentCost.DataList> subDataList = heatTreatmentCost.getDataList();
                        List<CommonQuotationPrice> list = subDataList.stream().map(sub -> {
                            CommonQuotationPrice commonQuotationPrice = new CommonQuotationPrice();
                            commonQuotationPrice.setId(IdUtils.simpleUUID());
                            commonQuotationPrice.setMoldSelectionId(moldSelectionId);
                            commonQuotationPrice.setDetailId(commonQuotationDetail.getId());
                            commonQuotationPrice.setType(NormalOutQuotationaSubEnum.HEAT_TREATMENT.getCn());
                            commonQuotationPrice.setName(sub.getItemName());
                            commonQuotationPrice.setNum(BigDecimal.valueOf(sub.getWeight()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setPrice(BigDecimal.valueOf(sub.getPrice()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setTotalPrice(BigDecimal.valueOf(sub.getTotalPrice()).stripTrailingZeros().toPlainString());
                            return commonQuotationPrice;
                        }).collect(Collectors.toList());
                        commonQuotationPriceList.addAll(list);
                    }
                    AssemlyMaterialCost assemlyMaterialCost = detailData.getAssemlyMaterialCost();
                    if (Objects.nonNull(assemlyMaterialCost) && Objects.nonNull(assemlyMaterialCost.getDataList())) {
                        List<AssemlyMaterialCost.DataList> subDataList = assemlyMaterialCost.getDataList();
                        List<CommonQuotationPrice> list = subDataList.stream().map(sub -> {
                            CommonQuotationPrice commonQuotationPrice = new CommonQuotationPrice();
                            commonQuotationPrice.setId(IdUtils.simpleUUID());
                            commonQuotationPrice.setMoldSelectionId(moldSelectionId);
                            commonQuotationPrice.setDetailId(commonQuotationDetail.getId());
                            commonQuotationPrice.setType(NormalOutQuotationaSubEnum.ASSEMLY_MATERIAL_COST.getCn());
                            commonQuotationPrice.setName(sub.getItemName());
                            commonQuotationPrice.setSupplier(sub.getSupplier());
                            commonQuotationPrice.setSpecification(sub.getSpecification());
                            commonQuotationPrice.setNum(BigDecimal.valueOf(sub.getCount()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setPrice(BigDecimal.valueOf(sub.getPrice()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setTotalPrice(BigDecimal.valueOf(sub.getTotalPrice()).stripTrailingZeros().toPlainString());
                            return commonQuotationPrice;
                        }).collect(Collectors.toList());
                        commonQuotationPriceList.addAll(list);
                    }
                    DesignFee designFee = detailData.getDesignFee();
                    if (Objects.nonNull(designFee) && Objects.nonNull(designFee.getDataList())) {
                        List<DesignFee.DataList> subDataList = designFee.getDataList();
                        List<CommonQuotationPrice> list = subDataList.stream().map(sub -> {
                            CommonQuotationPrice commonQuotationPrice = new CommonQuotationPrice();
                            commonQuotationPrice.setId(IdUtils.simpleUUID());
                            commonQuotationPrice.setMoldSelectionId(moldSelectionId);
                            commonQuotationPrice.setDetailId(commonQuotationDetail.getId());
                            commonQuotationPrice.setType(NormalOutQuotationaSubEnum.DESIGN_FEE.getCn());
                            commonQuotationPrice.setName(sub.getItemName());
                            commonQuotationPrice.setNum(BigDecimal.valueOf(sub.getHour()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setPrice(BigDecimal.valueOf(sub.getPrice()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setTotalPrice(BigDecimal.valueOf(sub.getTotalPrice()).stripTrailingZeros().toPlainString());
                            return commonQuotationPrice;
                        }).collect(Collectors.toList());
                        commonQuotationPriceList.addAll(list);
                    }
                    ManufacturingCost manufacturingCost = detailData.getManufacturingCost();
                    if (Objects.nonNull(manufacturingCost) && Objects.nonNull(manufacturingCost.getDataList())) {
                        List<ManufacturingCost.DataList> subDataList = manufacturingCost.getDataList();
                        List<CommonQuotationPrice> list = subDataList.stream().map(sub -> {
                            CommonQuotationPrice commonQuotationPrice = new CommonQuotationPrice();
                            commonQuotationPrice.setId(IdUtils.simpleUUID());
                            commonQuotationPrice.setMoldSelectionId(moldSelectionId);
                            commonQuotationPrice.setDetailId(commonQuotationDetail.getId());
                            commonQuotationPrice.setType(NormalOutQuotationaSubEnum.MANUFACTURING_COST.getCn());
                            commonQuotationPrice.setName(sub.getItemName());
                            commonQuotationPrice.setNum(BigDecimal.valueOf(sub.getHour()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setPrice(BigDecimal.valueOf(sub.getPrice()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setTotalPrice(BigDecimal.valueOf(sub.getTotalPrice()).stripTrailingZeros().toPlainString());
                            return commonQuotationPrice;
                        }).collect(Collectors.toList());
                        commonQuotationPriceList.addAll(list);
                    }
                    Cmmmeasure cmmmeasure = detailData.getCmmmeasure();
                    if (Objects.nonNull(cmmmeasure) && Objects.nonNull(cmmmeasure.getDataList())) {
                        List<Cmmmeasure.DataList> subDataList = cmmmeasure.getDataList();
                        List<CommonQuotationPrice> list = subDataList.stream().map(sub -> {
                            CommonQuotationPrice commonQuotationPrice = new CommonQuotationPrice();
                            commonQuotationPrice.setId(IdUtils.simpleUUID());
                            commonQuotationPrice.setMoldSelectionId(moldSelectionId);
                            commonQuotationPrice.setDetailId(commonQuotationDetail.getId());
                            commonQuotationPrice.setType(NormalOutQuotationaSubEnum.CMM_MEASURE.getCn());
                            commonQuotationPrice.setName(sub.getItemName());
                            commonQuotationPrice.setNum(BigDecimal.valueOf(sub.getHour()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setPrice(BigDecimal.valueOf(sub.getPrice()).stripTrailingZeros().toPlainString());
                            commonQuotationPrice.setTotalPrice(BigDecimal.valueOf(sub.getTotalPrice()).stripTrailingZeros().toPlainString());
                            return commonQuotationPrice;
                        }).collect(Collectors.toList());
                        commonQuotationPriceList.addAll(list);
                    }
                    OtherFee otherFee = detailData.getOtherFee();
                    if (Objects.nonNull(otherFee) && Objects.nonNull(otherFee.getDataList())) {
                        List<OtherFee.DataList> subDataList = otherFee.getDataList();
                        List<CommonQuotationPrice> list = subDataList.stream().map(sub -> {
                            CommonQuotationPrice commonQuotationPrice = new CommonQuotationPrice();
                            commonQuotationPrice.setId(IdUtils.simpleUUID());
                            commonQuotationPrice.setMoldSelectionId(moldSelectionId);
                            commonQuotationPrice.setDetailId(commonQuotationDetail.getId());
                            commonQuotationPrice.setType(NormalOutQuotationaSubEnum.OTHER_FEE.getCn());
                            commonQuotationPrice.setName(sub.getItemName());
                            commonQuotationPrice.setNum(sub.getFeeDesc());
                            commonQuotationPrice.setTotalPrice(BigDecimal.valueOf(sub.getTotalPrice()).stripTrailingZeros().toPlainString());
                            return commonQuotationPrice;
                        }).collect(Collectors.toList());
                        commonQuotationPriceList.addAll(list);
                    }
                } else {
                    commonQuotationDetailList.add(commonQuotationDetail);
                }
            });

            if (Objects.nonNull(commonQuotationDetailList) && !commonQuotationDetailList.isEmpty()) {
                commonQuotationDetailService.saveBatch(commonQuotationDetailList);
            }
            if (Objects.nonNull(commonQuotationPriceList) && !commonQuotationPriceList.isEmpty()) {
                commonQuotationPriceService.saveBatch(commonQuotationPriceList);
            }
        } catch (RuntimeException e) {
            log.error("保存通用报价单时失败:{}", e.toString(), e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JSON.toJSONString(R.fail(e.getMessage()));
        } catch (Exception e) {
            log.error("保存通用报价单时失败:{}", e.toString(), e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JSON.toJSONString(R.fail("保存失败"));
        }

        return JSON.toJSONString(R.data("保存成功"));
    }

    @Override
    public String getDFOutQuotation(JSONObject jsonObject) {
        if (jsonObject == null || jsonObject.size() < 1) {
            return JSONObject.toJSONString(R.fail("参数错误"));
        }
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        DfQuotationVo resp = new DfQuotationVo();
        //查询东风报价单信息
        LambdaQueryWrapper<DfQuotation> dfQuotationLambdaQueryWrapper = new QueryWrapper<DfQuotation>()
                .lambda()
                .eq(DfQuotation::getMoldSelectionId, moldSelectionId);
        DfQuotation dfQuotation = dfQuotationService.getOne(dfQuotationLambdaQueryWrapper);
        //初始化
        if (Objects.isNull(dfQuotation)) {
            LambdaQueryWrapper<TestModelParam> testModelParamLambdaQueryWrapper = new QueryWrapper<TestModelParam>()
                    .lambda()
                    .eq(TestModelParam::getMoldSelectionId, moldSelectionId)
                    .orderByAsc(TestModelParam::getMoldId);
            List<TestModelParam> modelParamList = testModelParamService.list(testModelParamLambdaQueryWrapper);
            if (!CollectionUtils.isEmpty(modelParamList)) {
                dfQuotation = new DfQuotation();
                dfQuotation.setId(IdUtils.simpleUUID());
                dfQuotation.setMoldSelectionId(moldSelectionId);
                dfQuotation.setProjectName(modelParamList.get(0).getProjectName());
                dfQuotationService.save(dfQuotation);
                for (TestModelParam testModelParam : modelParamList) {
                    DfQuotationDetail detail = new DfQuotationDetail();
                    detail.setId(IdUtils.simpleUUID());
                    detail.setQuotationId(dfQuotation.getId());
                    detail.setProductName(testModelParam.getProductName());
                    detail.setProductCode(testModelParam.getProductCode());
                    detail.setProductImage(testModelParam.getProductImage());
                    detail.setProductMaterial(testModelParam.getMaterials());
                    detail.setProductSize(testModelParam.getProductSize());
                    detail.setProductLength(testModelParam.getProductLength());
                    detail.setProductWidth(testModelParam.getProductWidth());
                    detail.setProductHeight(testModelParam.getProductHeight());
                    detail.setCavityNum(testModelParam.getCavityNum());
                    detail.setPour(testModelParam.getPour());
                    detail.setCavity(testModelParam.getCavity());
                    detail.setCore(testModelParam.getCore());
                    detail.setMoldBaseMaterial(null);
                    detail.setMovingParts(null);
                    detail.setMoldSize(testModelParam.getMoldSize());
                    detail.setMoldLength(testModelParam.getMoldLength());
                    detail.setMoldWidth(testModelParam.getMoldWidth());
                    detail.setMoldHeight(testModelParam.getMoldHeight());
                    detail.setDeviceId(testModelParam.getDeviceId());
                    detail.setDeviceName(testModelParam.getDeviceName());
                    detail.setMoldName(testModelParam.getMoldName());
                    detail.setSurface(testModelParam.getSurface());
                    dfQuotationDetailService.save(detail);

                    //初始化外部分表数据
                    List<DfQuotationPrice> priceList = Arrays.stream(NormalOutQuotationaPriceEnum.values()).map(normalOutQuotationaPriceEnum -> {
                        DfQuotationPrice price = new DfQuotationPrice();
                        price.setId(IdUtils.simpleUUID());
                        price.setDetailId(detail.getId());
                        price.setMoldSelectionId(moldSelectionId);
                        price.setType(normalOutQuotationaPriceEnum.getType());
                        price.setName(normalOutQuotationaPriceEnum.getItemName());
                        price.setPrice("0");
                        price.setLength("0");
                        price.setWidth("0");
                        price.setHeight("0");
                        price.setNum("0");
                        price.setTotalPrice("0");
                        return price;
                    }).collect(Collectors.toList());
                    dfQuotationPriceService.saveBatch(priceList);
                }

            }
        }
        if (Objects.nonNull(dfQuotation)) {
            resp.setEMail(dfQuotation.getEmail());
            resp.setFAX(dfQuotation.getFax());
            resp.setTEL(dfQuotation.getTel());
            resp.setZIP(dfQuotation.getZip());
            resp.setAddress(dfQuotation.getAddress());
            resp.setApprover(dfQuotation.getApprover());
            resp.setCheckoutName(dfQuotation.getAuditor());
            resp.setContactName(dfQuotation.getContact());
            resp.setContactPhone(dfQuotation.getPhone());
            resp.setFrom(dfQuotation.getFrom());
            resp.setMoldSelectionId(dfQuotation.getMoldSelectionId());
            resp.setMouldFeeTotal(dfQuotation.getMoldFee());
            resp.setPriceWithoutTaxIncludesSkinGrainTotal(StringUtils.isBlank(dfQuotation.getTextureFee()) ? 0.0 : Double.valueOf(dfQuotation.getMoldTotalFee()));
            resp.setProjectName(dfQuotation.getProjectName());
            resp.setQuotedPrice(dfQuotation.getMaker());
            resp.setTo(dfQuotation.getTo());
            resp.setUnit(dfQuotation.getUnit());
            resp.setWebsite(dfQuotation.getWebsite());
            resp.setTextureFeeTotal(StringUtils.isBlank(dfQuotation.getTextureFee()) ? 0.0 : Double.valueOf(dfQuotation.getTextureFee()));
            //处理东风报价详情逻辑
            LambdaQueryWrapper<DfQuotationDetail> dfQuotationDetailLambdaQueryWrapper = new QueryWrapper<DfQuotationDetail>()
                    .lambda()
                    .eq(DfQuotationDetail::getQuotationId, dfQuotation.getId())
                    .orderByAsc(DfQuotationDetail::getId);
            List<DfQuotationDetail> dfQuotationDetailList = dfQuotationDetailService.list(dfQuotationDetailLambdaQueryWrapper);
            DfQuotation finalDfQuotation = dfQuotation;
            List<DfObject> dfQuotationDetailResVoList = dfQuotationDetailList.stream().map(dfQuotationDetail -> {
                DfObject dfObject = new DfObject();
                dfObject.setSubTableId(dfQuotationDetail.getId());
                dfObject.setCavityCount(dfQuotationDetail.getCavityNum());
                dfObject.setCodeOfProduct(dfQuotationDetail.getProductCode());
                //详情表获取
                dfObject.setDeviceId(dfQuotationDetail.getDeviceId());
                dfObject.setHeightOfMold(StringUtils.isBlank(dfQuotationDetail.getMoldHeight()) ? 0 : Double.valueOf(dfQuotationDetail.getMoldHeight()));
                dfObject.setHeightOfProduct(StringUtils.isBlank(dfQuotationDetail.getProductHeight()) ? 0 : Double.valueOf(dfQuotationDetail.getProductHeight()));
                dfObject.setImageOfProduct(dfQuotationDetail.getProductImage());
                dfObject.setLengthOfMold(StringUtils.isBlank(dfQuotationDetail.getMoldLength()) ? 0 : Double.valueOf(dfQuotationDetail.getMoldLength()));
                dfObject.setLengthOfProduct(StringUtils.isBlank(dfQuotationDetail.getProductLength()) ? 0 : Double.valueOf(dfQuotationDetail.getProductLength()));
                dfObject.setLifetime(dfQuotationDetail.getLongevity());
                dfObject.setMaterialOfCavity(dfQuotationDetail.getCavity());
                dfObject.setMaterialOfCore(dfQuotationDetail.getCore());
                dfObject.setMaterials(dfQuotationDetail.getProductMaterial());

//                if(StringUtils.isNotBlank(dfQuotationDetail.getMoldFee())){
//                    double result = Double.valueOf(dfQuotationDetail.getMoldFee()) / 10000;
//                    String format = String.format("%.4f", result);
//                    dfObject.setMouldFee(StringUtils.isBlank(format)?0:Double.valueOf(format));
//                }else{
//                    dfObject.setMouldFee(0);
//                }
                dfObject.setMouldFee(StringUtils.isBlank(dfQuotationDetail.getMoldFee()) ? 0 : Double.valueOf(dfQuotationDetail.getMoldFee()));
                dfObject.setMouldIronMaterial(dfQuotationDetail.getMoldBaseMaterial());
                dfObject.setMouldTotalFee(StringUtils.isBlank(dfQuotationDetail.getMoldTotalFee()) ? 0 : Double.valueOf(dfQuotationDetail.getMoldTotalFee()));
                dfObject.setMovingParts(dfQuotationDetail.getMovingParts());
                dfObject.setNameOfProduct(dfQuotationDetail.getProductName());
                dfObject.setPourSystem(dfQuotationDetail.getPour());
                dfObject.setProductionCycle(dfQuotationDetail.getMakeTime());
                dfObject.setRemark(dfQuotationDetail.getRemark());
                dfObject.setWidthOfMold(StringUtils.isBlank(dfQuotationDetail.getMoldWidth()) ? 0 : Double.valueOf(dfQuotationDetail.getMoldWidth()));
                dfObject.setWidthOfProduct(StringUtils.isBlank(dfQuotationDetail.getProductWidth()) ? 0 : Double.valueOf(dfQuotationDetail.getProductWidth()));
                dfObject.setSurface(dfQuotationDetail.getSurface());

                dfObject.setProductWeight(StringUtils.isBlank(dfQuotationDetail.getProductWeight()) ? 0 : Double.valueOf(dfQuotationDetail.getProductWeight()));
                dfObject.setHydroCylinder(StringUtils.isBlank(dfQuotationDetail.getHydroCylinder()) ? 0 : Double.valueOf(dfQuotationDetail.getHydroCylinder()));
                dfObject.setEyeBolt(StringUtils.isBlank(dfQuotationDetail.getEyeBolt()) ? 0 : Double.valueOf(dfQuotationDetail.getEyeBolt()));
                dfObject.setTextureFee(StringUtils.isBlank(dfQuotationDetail.getTextureFee()) ? 0 : Double.valueOf(dfQuotationDetail.getTextureFee()));
                DfDetailData detailData = new DfDetailData();
                //首次试模时间/T0Time
                detailData.setT0Time(dfQuotationDetail.gett1Time());
                //型腔数量
                detailData.setCavityCount(dfQuotationDetail.getCavityNum());
                //产品零件号/Part No.
                detailData.setCodeOfProduct(dfQuotationDetail.getProductCode());

                //联系人
                detailData.setContacts(dfQuotationDetail.getContacts());
                //数据文件名/Drawing No.
                detailData.setDrawingNo(dfQuotationDetail.getDrawing());
                // 产品大小-高
                detailData.setHeightOfProduct(StringUtils.isBlank(dfQuotationDetail.getProductHeight()) ? 0 : Double.valueOf(dfQuotationDetail.getProductHeight()));
                //外形尺寸-高
                detailData.setHeightOfShape(StringUtils.isBlank(dfQuotationDetail.getMoldHeight()) ? 0 : Double.valueOf(dfQuotationDetail.getMoldHeight()));
                //最终交付时间/Lead Time
                detailData.setLeadTime(dfQuotationDetail.getLeadTime());
                //产品大小-长
                detailData.setLengthOfProduct(StringUtils.isBlank(dfQuotationDetail.getProductLength()) ? 0 : Double.valueOf(dfQuotationDetail.getProductLength()));
                //外形尺寸-长
                detailData.setLengthOfShape(StringUtils.isBlank(dfQuotationDetail.getMoldLength()) ? 0 : Double.valueOf(dfQuotationDetail.getMoldLength()));
                //模具寿命/Longevity
                detailData.setLongevity(dfQuotationDetail.getMoldLongevity());
                //模具名称
                detailData.setMoldName(dfQuotationDetail.getMoldName());
                //模具重量
                detailData.setMoldWeight(StringUtils.isBlank(dfQuotationDetail.getMoldWeight()) ? 0 : Double.valueOf(dfQuotationDetail.getMoldWeight()));
                //模具总价(元) (RMB)

                if (StringUtils.isBlank(dfQuotationDetail.getMoldFee())) {
                    detailData.setMouldFee(0);
                } else {
                    BigDecimal bigDecimal = new BigDecimal(dfQuotationDetail.getMoldFee()).multiply(new BigDecimal(10000)).setScale(4, RoundingMode.HALF_UP);
                    detailData.setMouldFee(bigDecimal.doubleValue());
                }

                if (StringUtils.isBlank(dfQuotationDetail.getMoldTotalFee())) {
                    detailData.setTotalPrice(0);
                } else {
                    BigDecimal bigDecimal = new BigDecimal(dfQuotationDetail.getMoldTotalFee()).multiply(new BigDecimal(10000)).setScale(4, RoundingMode.HALF_UP);
                    detailData.setTotalPrice(bigDecimal.doubleValue());
                }
                //detailData.setMouldFee(StringUtils.isBlank(dfQuotationDetail.getMoldTotalFee())?0:Double.valueOf(dfQuotationDetail.getMoldTotalFee()));
                //detailData.setTotalPrice(StringUtils.isBlank(dfQuotationDetail.getTotalFee())?0:Double.valueOf(dfQuotationDetail.getTotalFee()));

                //设备吨位/Press(Ton)
                detailData.setPressTon(dfQuotationDetail.getPress());
                //皮纹价格（元）RMB
                detailData.setSkinGrainFee(StringUtils.isBlank(dfQuotationDetail.getTextureFee()) ? 0 : Double.valueOf(dfQuotationDetail.getTextureFee()));
                //电话/tel
                detailData.setPhone(dfQuotationDetail.getPhone());

                // 产品重量
                detailData.setWeightOfProduct(StringUtils.isBlank(dfQuotationDetail.getProductWeight()) ? 0 : Double.valueOf(dfQuotationDetail.getProductWeight()));
                //产品大小-宽
                detailData.setWidthOfProduct(StringUtils.isBlank(dfQuotationDetail.getProductWidth()) ? 0 : Double.valueOf(dfQuotationDetail.getProductWidth()));
                //外形尺寸-宽
                detailData.setWidthOfShape(StringUtils.isBlank(dfQuotationDetail.getMoldWidth()) ? 0 : Double.valueOf(dfQuotationDetail.getMoldWidth()));
                detailData.setT0Time(dfQuotationDetail.gett1Time());
                detailData.setStamp(dfQuotationDetail.getStamp());
                detailData.setDate(dfQuotationDetail.getDate());
                detailData.setSupplier(dfQuotationDetail.getSupplier());
                detailData.setSignature(dfQuotationDetail.getSignature());
                detailData.setPhone(dfQuotationDetail.getPhone());
                //查询分表数据
                LambdaQueryWrapper<DfQuotationPrice> dfQuotationPriceLambdaQueryWrapper = new QueryWrapper<DfQuotationPrice>()
                        .lambda()
                        .eq(DfQuotationPrice::getDetailId, dfQuotationDetail.getId())
                        .orderByAsc(DfQuotationPrice::getId);
                List<DfQuotationPrice> dfQuotationPriceList = dfQuotationPriceService.list(dfQuotationPriceLambdaQueryWrapper);
                Map<String, List<DfQuotationPrice>> subMap = dfQuotationPriceList.stream().collect(Collectors.groupingBy(DfQuotationPrice::getType, LinkedHashMap::new, Collectors.toList()));
                for (Map.Entry<String, List<DfQuotationPrice>> stringListEntry : subMap.entrySet()) {
                    String itemName = stringListEntry.getKey();
                    List<DfQuotationPrice> list = stringListEntry.getValue();

                    if (itemName.equals(NormalOutQuotationaSubEnum.MACHINING_MATERIAL_COST.getCn())) {
                        DfMachiningMaterialCost machiningMaterialCost = new DfMachiningMaterialCost();
                        List<ItemMach> dataList = Lists.newArrayList();
                        for (DfQuotationPrice price : list) {
                            ItemMach itemMach = new ItemMach();
                            //尺寸-高/Size(mm×mm×mm)
                            itemMach.setHeight(StringUtils.isBlank(price.getHeight()) ? 0 : Double.valueOf(price.getHeight()));
                            //材料名称/Material
                            itemMach.setItemName(price.getName());
                            //尺寸-长/Size(mm×mm×mm)
                            itemMach.setLength(StringUtils.isBlank(price.getLength()) ? 0 : Double.valueOf(price.getLength()));
                            //单价(元)/Unit Price(RMB)
                            itemMach.setPrice(StringUtils.isBlank(price.getPrice()) ? 0 : Double.valueOf(price.getPrice()));
                            //材料牌号/Specification
                            itemMach.setSpecification(price.getSpecification());
                            //金额(元)/Price(RMB)
                            itemMach.setTotalPrice(StringUtils.isBlank(price.getTotalPrice()) ? 0 : Double.valueOf(price.getTotalPrice()));
                            //重量/Weight(Kg)
                            itemMach.setWeight(StringUtils.isBlank(price.getNum()) ? 0 : Double.valueOf(price.getNum()));
                            //尺寸-宽/Size(mm×mm×mm)
                            itemMach.setWidth(StringUtils.isBlank(price.getWidth()) ? 0 : Double.valueOf(price.getWidth()));
                            dataList.add(itemMach);
                        }
                        machiningMaterialCost.setDataList(dataList);
                        machiningMaterialCost.setSubTotal(StringUtils.isBlank(dfQuotationDetail.getMachiningMaterialCost()) ? 0 : Double.valueOf(dfQuotationDetail.getMachiningMaterialCost()));
                        detailData.setMachiningMaterialCost(machiningMaterialCost);
                    }
                    if (itemName.equals(NormalOutQuotationaSubEnum.HEAT_TREATMENT.getCn())) {
                        DfHeatTreatmentCost heatTreatmentCost = new DfHeatTreatmentCost();
                        List<ItemHeat> dataList = Lists.newArrayList();
                        for (DfQuotationPrice price : list) {
                            ItemHeat itemHeat = new ItemHeat();
                            //材料名称/Material
                            itemHeat.setItemName(price.getName());
                            //单价(元)/Unit Price(RMB)
                            itemHeat.setPrice(StringUtils.isBlank(price.getPrice()) ? 0 : Double.valueOf(price.getPrice()));
                            //金额(元)/Price(RMB)
                            itemHeat.setTotalPrice(StringUtils.isBlank(price.getTotalPrice()) ? 0 : Double.valueOf(price.getTotalPrice()));
                            //重量/Weight(Kg)
                            itemHeat.setWeight(StringUtils.isBlank(price.getNum()) ? 0 : Double.valueOf(price.getNum()));
                            dataList.add(itemHeat);
                        }
                        heatTreatmentCost.setDataList(dataList);
                        heatTreatmentCost.setSubTotal(StringUtils.isBlank(dfQuotationDetail.getHeatTreatment()) ? 0 : Double.valueOf(dfQuotationDetail.getHeatTreatment()));
                        detailData.setHeatTreatmentCost(heatTreatmentCost);
                    }
                    if (itemName.equals(NormalOutQuotationaSubEnum.ASSEMLY_MATERIAL_COST.getCn())) {
                        DfAssemlyMaterialCost assemlyMaterialCost = new DfAssemlyMaterialCost();
                        List<ItemAssemly> dataList = Lists.newArrayList();
                        for (DfQuotationPrice price : list) {
                            ItemAssemly itemAssemly = new ItemAssemly();
                            //装配件名称/Item
                            itemAssemly.setItemName(price.getName());
                            //规格型号/Specification
                            itemAssemly.setSpecification(price.getSpecification());
                            //品牌/Supplier
                            itemAssemly.setSupplier(price.getSupplier());
                            //数量
                            itemAssemly.setCount(StringUtils.isBlank(price.getNum()) ? 0 : Double.valueOf(price.getNum()));
                            //单价(元)/Unit Price(RMB)
                            itemAssemly.setPrice(StringUtils.isBlank(price.getPrice()) ? 0 : Double.valueOf(price.getPrice()));
                            //金额(元)/Price(RMB)
                            itemAssemly.setTotalPrice(StringUtils.isBlank(price.getTotalPrice()) ? 0 : Double.valueOf(price.getTotalPrice()));
                            dataList.add(itemAssemly);
                        }
                        assemlyMaterialCost.setDataList(dataList);
                        assemlyMaterialCost.setSubTotal(StringUtils.isBlank(dfQuotationDetail.getAssemlyMaterialCost()) ? 0 : Double.valueOf(dfQuotationDetail.getAssemlyMaterialCost()));
                        detailData.setAssemlyMaterialCost(assemlyMaterialCost);
                    }
                    if (itemName.equals(NormalOutQuotationaSubEnum.DESIGN_FEE.getCn())) {
                        DfDesignCost designCost = new DfDesignCost();
                        List<ItemDesign> dataList = Lists.newArrayList();
                        for (DfQuotationPrice price : list) {
                            ItemDesign itemDesign = new ItemDesign();
                            itemDesign.setHour(StringUtils.isBlank(price.getNum()) ? 0 : Integer.valueOf(price.getNum()));
                            //装配件名称/Item
                            itemDesign.setItemName(price.getName());
                            //单价(元)/Unit Price(RMB)
                            itemDesign.setPrice(StringUtils.isBlank(price.getPrice()) ? 0 : Double.valueOf(price.getPrice()));
                            //金额(元)/Price(RMB)
                            itemDesign.setTotalPrice(StringUtils.isBlank(price.getTotalPrice()) ? 0 : Double.valueOf(price.getTotalPrice()));
                            dataList.add(itemDesign);
                        }
                        designCost.setDataList(dataList);
                        designCost.setSubTotal(StringUtils.isBlank(dfQuotationDetail.getDesignCost()) ? 0 : Double.valueOf(dfQuotationDetail.getDesignCost()));
                        detailData.setDesignCost(designCost);
                    }
                    if (itemName.equals(NormalOutQuotationaSubEnum.MANUFACTURING_COST.getCn())) {
                        DfManufacturingCost manufacturingCost = new DfManufacturingCost();
                        List<ItemManufacturing> dataList = Lists.newArrayList();
                        for (DfQuotationPrice price : list) {
                            ItemManufacturing itemManufacturing = new ItemManufacturing();
                            itemManufacturing.setHour(StringUtils.isBlank(price.getNum()) ? 0 : Double.valueOf(price.getNum()));
                            //装配件名称/Item
                            itemManufacturing.setItemName(price.getName());
                            //单价(元)/Unit Price(RMB)
                            itemManufacturing.setPrice(StringUtils.isBlank(price.getPrice()) ? 0 : Double.valueOf(price.getPrice()));
                            //金额(元)/Price(RMB)
                            itemManufacturing.setTotalPrice(StringUtils.isBlank(price.getTotalPrice()) ? 0 : Double.valueOf(price.getTotalPrice()));
                            dataList.add(itemManufacturing);
                        }
                        manufacturingCost.setDataList(dataList);
                        manufacturingCost.setSubTotal(StringUtils.isBlank(dfQuotationDetail.getManufacturingCost()) ? 0 : Double.valueOf(dfQuotationDetail.getManufacturingCost()));
                        detailData.setManufacturingCost(manufacturingCost);
                    }
                    if (itemName.equals(NormalOutQuotationaSubEnum.CMM_MEASURE.getCn())) {
                        DfCMMMeasure cMMMeasure = new DfCMMMeasure();
                        List<ItemCMMM> dataList = Lists.newArrayList();
                        for (DfQuotationPrice price : list) {
                            ItemCMMM itemCMMM = new ItemCMMM();
                            itemCMMM.setHour(StringUtils.isBlank(price.getNum()) ? 0 : Double.valueOf(price.getNum()));
                            //装配件名称/Item
                            itemCMMM.setItemName(price.getName());
                            //单价(元)/Unit Price(RMB)
                            itemCMMM.setPrice(StringUtils.isBlank(price.getPrice()) ? 0 : Double.valueOf(price.getPrice()));
                            //金额(元)/Price(RMB)
                            itemCMMM.setTotalPrice(StringUtils.isBlank(price.getTotalPrice()) ? 0 : Double.valueOf(price.getTotalPrice()));
                            dataList.add(itemCMMM);
                        }
                        cMMMeasure.setDataList(dataList);
                        cMMMeasure.setSubTotal(StringUtils.isBlank(dfQuotationDetail.getCmmMeasure()) ? 0 : Double.valueOf(dfQuotationDetail.getCmmMeasure()));
                        detailData.setCMMMeasure(cMMMeasure);
                    }
                    if (itemName.equals(NormalOutQuotationaSubEnum.OTHER_FEE.getCn())) {
                        DfOtherFee otherFee = new DfOtherFee();
                        List<ItemOther> dataList = Lists.newArrayList();
                        for (DfQuotationPrice price : list) {
                            ItemOther itemOther = new ItemOther();
                            //费用计算说明
                            itemOther.setFeeDesc(price.getNum());
                            //费用名称
                            itemOther.setFeeName(price.getName());
                            //单价(元)
                            itemOther.setPrice(StringUtils.isBlank(price.getPrice()) ? 0 : Double.valueOf(price.getPrice()));
                            //金额(元)
                            itemOther.setTotalPrice(StringUtils.isBlank(price.getTotalPrice()) ? 0 : Double.valueOf(price.getTotalPrice()));
                            dataList.add(itemOther);
                        }
                        otherFee.setDataList(dataList);
                        otherFee.setSubTotal(StringUtils.isBlank(dfQuotationDetail.getOtherFee()) ? 0 : Double.valueOf(dfQuotationDetail.getOtherFee()));
                        detailData.setOtherFee(otherFee);
                    }
                }
                dfObject.setDetailData(detailData);
                return dfObject;
            }).collect(Collectors.toList());
            resp.setDataList(dfQuotationDetailResVoList);
        }
        return JSONObject.toJSONString(R.data(resp, "获取成功"), SerializerFeature.WriteMapNullValue);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String saveInnerQuotation(JSONObject jsonObject) {
        try {
            //jsonobject解析获取选模表Id
            String moldSelectionId = jsonObject.getString("moldSelectionId");
            if (StringUtils.isEmpty(moldSelectionId)) {
                return JSON.toJSONString(R.fail("参数错误，选模表Id不能为空"));
            }

            if (null != jsonObject) {
                //验证是否存在数据
                InnerQuotation innerQuotation = innerQuotationService.getOne(new LambdaQueryWrapper<InnerQuotation>().eq(InnerQuotation::getMoldSelectionId, moldSelectionId));
                if (Objects.nonNull(innerQuotation)) {
                    if ("1".equals(innerQuotation.getStatus())) {
                        return JSON.toJSONString(R.fail("提交状态，无法更改"));
                    }
                    List<InnerQuotationDetail> detail = iInnerQuotationDetailService.list(new QueryWrapper<InnerQuotationDetail>().lambda().eq(InnerQuotationDetail::getMoldSelectionId, moldSelectionId));

                    //删除数据
                    innerQuotationService.remove(new LambdaQueryWrapper<InnerQuotation>().eq(InnerQuotation::getId, innerQuotation.getId()));
                    iInnerQuotationDetailService.remove(new QueryWrapper<InnerQuotationDetail>().lambda().eq(InnerQuotationDetail::getMoldSelectionId, moldSelectionId));
                    if (detail.size() > 0) {
                        List<String> moldIds = detail.stream().map(InnerQuotationDetail::getMoldId).collect(Collectors.toList());
                        iInnerQuotationPartPriceService.remove(new QueryWrapper<InnerQuotationPartPrice>().lambda().in(InnerQuotationPartPrice::getMoldId, moldIds));
                        partPriceService.remove(new QueryWrapper<PartPrice>().lambda().in(PartPrice::getMoldId, moldIds));
                    }
                }
                //json转实体
                ReqInnerQuoDetailsVO detailsVO = jsonObject.toJavaObject(ReqInnerQuoDetailsVO.class);
                //保存内部报价主表 t_inner_quotation表
                saveInnerQuotation(moldSelectionId, detailsVO);
                //解析数据 并保存 t_inner_quotation_detail表、t_inner_quotation_part_price、t_part_price表
                List<String> moldIdList = Lists.newArrayList(); //判断 moldId 是否重复
                for (InnerBaseInfo inner : detailsVO.getDataList()) {

                    InnerQuotationDetail detail = new InnerQuotationDetail();

                    //详情数据
                    DetailData detailData = inner.getDetailData();
                    String moldId = inner.getMoldId();
                    //判断 moldId 是否重复
                    if (moldIdList.contains(moldId)) {
                        throw new Exception("moldId 是否重复");
                    } else {
                        moldIdList.add(moldId);
                    }
                    //保存内部报价详情表
                    detail.setId(IdUtils.simpleUUID());
                    detail.setMoldSelectionId(inner.getMoldSelectionId());
                    detail.setMoldTypeId(detailData.getMoldTypeId());
                    detail.setProductName(inner.getNameOfProduct());
                    detail.setMoldId(inner.getMoldId());
                    detail.setProductImage(inner.getImageOfProduct());

                    //产品尺寸
                    String productSize = inner.getLengthOfProduct() + "*" + inner.getWidthOfProduct() + "*" + inner.getHeightOfProduct();
                    detail.setProductSize(productSize);


                    detail.setProductLength(Objects.isNull(inner.getLengthOfProduct()) ? "" : String.valueOf(inner.getLengthOfProduct()));
                    detail.setProductWidth(Objects.isNull(inner.getWidthOfProduct()) ? "" : String.valueOf(inner.getWidthOfProduct()));
                    detail.setProductHeight(Objects.isNull(inner.getHeightOfProduct()) ? "" : String.valueOf(inner.getHeightOfProduct()));
                    detail.setCore(inner.getMaterialOfCavity());
                    detail.setPour(inner.getHotRunnerBrand());
                    detail.setCavityNum(inner.getPerCavitiesOfMold());
                    //需求：AB板及主材 == 分表零件列表中字段为 isMainMaterial = true所有总价
                    BigDecimal mainMaterialFee = new BigDecimal(0.00);
                    for (MoldPart moldPart : inner.getDetailData().getMoldPartList()) {
                        if (moldPart.getIsMainMaterial()) {
                            mainMaterialFee = mainMaterialFee.add(new BigDecimal(moldPart.getTotalPrice()));
                        }
                    }
                    int comparisonResult = mainMaterialFee.setScale(2, RoundingMode.HALF_UP)
                            .compareTo(new BigDecimal(inner.getMainMaterialsFee()).setScale(2, RoundingMode.HALF_UP));
                    if (comparisonResult != 0) {
                        throw new RuntimeException("AB板及主材费用计算错误.正确值为：" + mainMaterialFee.setScale(2, RoundingMode.HALF_UP));
                    }
                    detail.setMainMaterialFee(Objects.isNull(inner.getMainMaterialsFee()) ? "" : String.valueOf(inner.getMainMaterialsFee()));
                    //模架
                    detail.setMouldFee(Objects.isNull(inner.getMouldFee()) ? "" : String.valueOf(inner.getMouldFee()));


                    //一、小钢料 设置变量 (大斜顶上的推块+小斜顶+小直顶+推块)
                    BigDecimal ironMaterialFee = new BigDecimal("0.00");
                    //0、标准价 设置变量
                    BigDecimal standardComponentFee = new BigDecimal("0.00");
                    for (MoldPart moldPart : detailData.getMoldPartList()) {
                        if ("推块（大斜顶上的）".equals(moldPart.getPartName())) {
                            ironMaterialFee = ironMaterialFee.add(new BigDecimal(moldPart.getTotalPrice()));
                        }
                        if (moldPart.getIsStandardCom()) {
                            //1、标准价 （标准价+ 零件标准件总价）
                            standardComponentFee = standardComponentFee.add(new BigDecimal(moldPart.getTotalStandardComponentCost()));
                        }
                    }
                    for (IronMaterial ironMaterial : detailData.getIronMaterialList()) {
                        if ("小斜顶".equals(ironMaterial.getIronMaterialsName()) ||
                                "小直顶".equals(ironMaterial.getIronMaterialsName()) || "推块".equals(ironMaterial.getIronMaterialsName())) {
                            //二、 小刚料（标准价+ 零件标准件费总价）
                            if (null != ironMaterial.getMaterialTotalPrice()) {
                                ironMaterialFee = ironMaterialFee.add(new BigDecimal(ironMaterial.getMaterialTotalPrice()));
                            }
                            //2、标准价 （标准价+ 小刚料标准价）
                            if (null != ironMaterial.getTotalStandardComponentCost()) {
                                standardComponentFee = standardComponentFee.add(new BigDecimal(ironMaterial.getTotalStandardComponentCost()));
                            }

                        }
                    }
                    //三、小刚料 验证是否正确
                    int ironMaterialFeeFlag = ironMaterialFee.setScale(2, RoundingMode.HALF_UP)
                            .compareTo(new BigDecimal(inner.getIronMaterialsFee()).setScale(2, RoundingMode.HALF_UP));
                    if (ironMaterialFeeFlag != 0) {
                        log.error("小钢料(大斜顶上的推块+小斜顶+小直顶+推块)计算错误.正确值为：" + ironMaterialFee);
                        throw new RuntimeException("小钢料(大斜顶上的推块+小斜顶+小直顶+推块)计算错误.正确值为：" + ironMaterialFee);
                    }
                    //四、小刚料 赋值
                    detail.setIronMaterialFee(Objects.isNull(inner.getIronMaterialsFee()) ? "" : String.valueOf(inner.getIronMaterialsFee()));

                    //3、标准价 (标准件 + 接油头)
                    if (null != detailData.getThimblePrice()) {
                        standardComponentFee = standardComponentFee.add(new BigDecimal(detailData.getThimblePrice()));
                    }
                    //4、标准价 (标准件 + 油缸)
                    standardComponentFee = standardComponentFee.add(new BigDecimal(detailData.getOilCylinder().getTotalPrice()));

                    //5、标准价 验证 标准价是否正确
                    int standardComponentFeeFlag = standardComponentFee.setScale(2, RoundingMode.HALF_UP)
                            .compareTo(new BigDecimal(inner.getStandardComponentFee()).setScale(2, RoundingMode.HALF_UP));

                    if (standardComponentFeeFlag != 0) {
                        log.error("标准价计算错误:零件+小刚料+接油头+油缸.正确值为：" + standardComponentFee);
                        throw new RuntimeException("标准价计算错误:零件+小刚料+接油头+油缸.正确值为：" + standardComponentFee.setScale(2, RoundingMode.HALF_UP));
                    }
                    //6、 标准价 赋值
                    detail.setStandardComponentFee(Objects.isNull(inner.getStandardComponentFee()) ? "" : String.valueOf(inner.getStandardComponentFee()));

                    //1、外协费 （所有零件 制造费用+小刚料的价格之和）
                    BigDecimal outsourceFee = new BigDecimal("0.00");
                    //2、外协费 （所有零件 制造费用之和）
                    for (MoldPart moldPart : inner.getDetailData().getMoldPartList()) {
                        outsourceFee = outsourceFee.add(new BigDecimal(moldPart.getManufacturingFee()));

                    }
                    //3、外协费（小刚料的价格之和）
                    for (IronMaterial ironMaterial : inner.getDetailData().getIronMaterialList()) {
                        if (null != ironMaterial.getMaterialTotalPrice()) {
                            outsourceFee = outsourceFee.add(new BigDecimal(ironMaterial.getTotalProcessPrice()));
                        }
                    }
                    //4、验证是否正确
                    int outsourceFeeFlag = outsourceFee.setScale(2, RoundingMode.HALF_UP)
                            .compareTo(new BigDecimal(inner.getOutsourceFee()).setScale(2, RoundingMode.HALF_UP));
                    if (outsourceFeeFlag != 0) {
                        log.error("外协费计算错误.正确值为：" + outsourceFee.setScale(2, RoundingMode.HALF_UP));
                        throw new RuntimeException("外协费计算错误.正确值为：" + outsourceFee.setScale(2, RoundingMode.HALF_UP));
                    }
                    //5、赋值
                    detail.setOutsourceFee(Objects.isNull(inner.getOutsourceFee()) ? "" : String.valueOf(inner.getOutsourceFee()));
                    //费用详情中的热流道的价格 =热流道数量*热流道价格
                    detail.setHotRunnerFee(Objects.isNull(inner.getHotRunnerAimFee()) ? "" : String.valueOf(inner.getHotRunnerAimFee()));
                    detail.setBoughtInComponents(Objects.isNull(inner.getBoughtInComponents()) ? "" : String.valueOf(inner.getBoughtInComponents()));
                    detail.setTextureFee(Objects.isNull(inner.getTexturingAimFee()) ? "" : String.valueOf(inner.getTexturingAimFee()));
                    detail.setPlasticFee(Objects.isNull(inner.getPlasticMaterialAimFee()) ? "" : String.valueOf(inner.getPlasticMaterialAimFee()));
                    detail.setAssemblyFee(Objects.isNull(inner.getAssemblyFee()) ? "" : String.valueOf(inner.getAssemblyFee()));
                    detail.setTryoutFee(Objects.isNull(inner.getTryoutFee()) ? "" : String.valueOf(inner.getTryoutFee()));
                    detail.setTransportFee(Objects.isNull(inner.getTransportFee()) ? "" : String.valueOf(inner.getTransportFee()));
                    detail.setManufacturingFee(Objects.isNull(inner.getManufacturingFee()) ? "" : String.valueOf(inner.getManufacturingFee()));
                    detail.setPeriodFee(Objects.isNull(inner.getPeriodRectificationFee()) ? "" : String.valueOf(inner.getPeriodRectificationFee()));
                    detail.setPriceWithoutTax(Objects.isNull(inner.getFinalTaxNotIncluded()) ? "" : String.valueOf(inner.getFinalTaxNotIncluded()));
                    detail.setGrossProfit(Objects.isNull(inner.getTargetGrossProfit()) ? "" : String.valueOf(inner.getTargetGrossProfit()));


                    detail.setGrossProfitRatio(inner.getPercentageOfFinalProcessTargetGrossProfit());
                    detail.setTryoutTimes(inner.getTryoutTimes());
                    iInnerQuotationDetailService.save(detail);

                    //保存内部报价价格表 t_inner_quotation_part_price 表
                    InnerQuotationPartPrice quotationPartPrice = new InnerQuotationPartPrice();
                    for (IronMaterial ironMaterial : detailData.getIronMaterialList()) {
                        quotationPartPrice.setId(IdUtils.simpleUUID());
                        quotationPartPrice.setMoldId(moldId);
                        quotationPartPrice.setName(ironMaterial.getIronMaterialsName());
                        quotationPartPrice.setCount(Objects.isNull(ironMaterial.getCount()) ? "" : String.valueOf(ironMaterial.getCount()));
                        quotationPartPrice.setTotalPrice(Objects.isNull(ironMaterial.getMaterialTotalPrice()) ? "" : String.valueOf(ironMaterial.getMaterialTotalPrice()));
                        quotationPartPrice.setPrice(Objects.isNull(ironMaterial.getPrice()) ? "" : String.valueOf(ironMaterial.getPrice()));
                        //加工费单价
                        quotationPartPrice.setProcessPrice(Objects.isNull(ironMaterial.getProcessPrice()) ? "" : String.valueOf(ironMaterial.getProcessPrice()));
                        //加工费总价
                        quotationPartPrice.setTotalProcessPrice(Objects.isNull(ironMaterial.getTotalProcessPrice()) ? "" : String.valueOf(ironMaterial.getTotalProcessPrice()));
                        //标准件费单价
                        quotationPartPrice.setStandardComponentFee(Objects.isNull(ironMaterial.getStandardComponent()) ? "" : String.valueOf(ironMaterial.getStandardComponent()));
                        //标准件费总价
                        quotationPartPrice.setTotalStandardComponentFee(Objects.isNull(ironMaterial.getTotalStandardComponentCost()) ? "" : String.valueOf(ironMaterial.getTotalStandardComponentCost()));
                        iInnerQuotationPartPriceService.save(quotationPartPrice);
                    }
                    //装配费用
                    AssemblyFee assemblyFee = detailData.getAssemblyFeeOfDetail();
                    //热流道
                    HotRunner hotRunner = detailData.getHotRunner();
                    //油缸
                    OilCylinder oilCylinder = detailData.getOilCylinder();
                    //纹理价格
                    TexturingCost texturingCost = detailData.getTexturingCost();
                    //塑料材料
                    PlasticMaterialCost plasticMaterialCost = detailData.getPlasticMaterialCost();
                    //试模费用
                    TryoutFee tryoutFee = detailData.getTryoutFeeOfDetail();
                    List<MoldPart> moldPartList = detailData.getMoldPartList();
                    //零件列表
                    List<PartPrice> moldParts = Lists.newArrayList();
                    for (MoldPart moldPart : moldPartList) {
                        PartPrice partPrice = new PartPrice();
                        if (StringUtils.isEmpty(moldPart.getId())) {
                            partPrice.setId(IdUtils.simpleUUID());
                        }
                        partPrice.setMoldId(moldId);
                        partPrice.setNum(String.valueOf(moldPart.getCountOfPart()));
                        partPrice.setDensity(String.valueOf(moldPart.getDensityOfPart()));
                        partPrice.setHeight(String.valueOf(moldPart.getHeightOfPart()));
                        partPrice.setIsMoldFrame(moldPart.getIsMoldFrame());
                        partPrice.setLength(String.valueOf(moldPart.getLengthOfPart()));
                        partPrice.setCosts(String.valueOf(moldPart.getManufacturingFee()));
                        partPrice.setPartId(moldPart.getPartId());
                        partPrice.setPartName(moldPart.getPartName());
                        partPrice.setPrice(String.valueOf(moldPart.getPriceOfPart()));
                        partPrice.setTotalPrice(String.valueOf(moldPart.getTotalPrice()));
                        partPrice.setWeight(String.valueOf(moldPart.getWeightOfPart()));
                        partPrice.setWidth(String.valueOf(moldPart.getWidthOfPart()));
                        partPrice.setIsMainMaterial(moldPart.getIsMainMaterial());
                        partPrice.setIsStandardCom(moldPart.getIsStandardCom());
                        partPrice.setIsRequired(moldPart.getIsRequired());
                        partPrice.setType("1");
                        partPrice.setStandardComponentFee(String.valueOf(moldPart.getTotalStandardComponentCost()));
                        moldParts.add(partPrice);
                    }
                    savePartPriceBatch(moldParts);

                    //标准件 接油头
                    Double thimblePrice = detailData.getThimblePrice();
                    if (null != thimblePrice) {
                        savePartPrice(moldId, null, null, null, thimblePrice, InnerOtherEnum.SEVEN.getName());
                    }
                    //运输费用
                    Double transportFeeOfDetail = detailData.getTransportFeeOfDetail();
                    if (null != transportFeeOfDetail) {
                        savePartPrice(moldId, null, null, transportFeeOfDetail, null, InnerOtherEnum.ELEVEN.getName());
                    }
                    //外购件-检具价格
                    Double gagePrice = detailData.getGagePrice();
                    if (null != gagePrice) {
                        savePartPrice(moldId, null, null, gagePrice, null, InnerOtherEnum.EIGHT.getName());
                    }
                    //外购件-石墨电极价格
                    Double graphiteElectrodeCost = detailData.getGraphiteElectrodeCost();
                    if (null != graphiteElectrodeCost) {
                        savePartPrice(moldId, null, null, graphiteElectrodeCost, null, InnerOtherEnum.NINE.getName());
                    }
                    //模架
                    MoldInfo mouldInfo = detailData.getMouldInfo();
                    if (null != mouldInfo) {
                        PartPrice partPrice = new PartPrice();
                        partPrice.setId(IdUtils.simpleUUID());
                        partPrice.setMoldId(moldId);
                        partPrice.setNum(Objects.isNull(mouldInfo.getCount()) ? "" : String.valueOf(mouldInfo.getCount()));
                        partPrice.setHeight(Objects.isNull(mouldInfo.getHeightOfMould()) ? "" : String.valueOf(mouldInfo.getHeightOfMould()));
                        partPrice.setLength(Objects.isNull(mouldInfo.getLengthOfMould()) ? "" : String.valueOf(mouldInfo.getLengthOfMould()));
                        partPrice.setPrice(Objects.isNull(mouldInfo.getPrice()) ? "" : String.valueOf(mouldInfo.getPrice()));
                        partPrice.setTotalPrice(Objects.isNull(mouldInfo.getTotalPrice()) ? "" : String.valueOf(mouldInfo.getTotalPrice()));
                        partPrice.setWidth(Objects.isNull(mouldInfo.getWidthOfMould()) ? "" : String.valueOf(mouldInfo.getWidthOfMould()));
                        partPrice.setPartName(InnerOtherEnum.TEN.getName());
                        partPrice.setType("3");
                        partPriceService.save(partPrice);
                    }
                    //装配费用
                    if (null != assemblyFee) {
                        String num = String.valueOf(assemblyFee.getNum());
                        savePartPrice(moldId, num, assemblyFee.getPrice(), assemblyFee.getTotalPrice(), null, InnerOtherEnum.ONE.getName());
                    }
                    //热流道
                    if (null != hotRunner) {
                        String num = String.valueOf(hotRunner.getNum());
                        savePartPrice(moldId, num, hotRunner.getPrice(), hotRunner.getTotalPrice(), null, InnerOtherEnum.TWO.getName());
                    }
                    //油缸
                    if (null != oilCylinder) {
                        String num = String.valueOf(oilCylinder.getNum());
                        savePartPrice(moldId, num, oilCylinder.getPrice(), oilCylinder.getTotalPrice(), oilCylinder.getTotalPrice(), InnerOtherEnum.THREE.getName());
                    }
                    //纹理价格
                    if (null != texturingCost) {
                        String num = String.valueOf(texturingCost.getArea());
                        savePartPrice(moldId, num, texturingCost.getPrice(), texturingCost.getTotalPrice(), null, InnerOtherEnum.FIVE.getName());
                    }
                    //塑胶材料
                    if (null != plasticMaterialCost) {
                        PartPrice partPrice = new PartPrice();
                        partPrice.setId(IdUtils.simpleUUID());
                        partPrice.setMoldId(moldId);
                        partPrice.setPartName(InnerOtherEnum.FOUR.getName());
                        partPrice.setWeight(Objects.isNull(plasticMaterialCost.getWeight()) ? "" : String.valueOf(plasticMaterialCost.getWeight()));
                        partPrice.setPrice(Objects.isNull(plasticMaterialCost.getPrice()) ? "" : String.valueOf(plasticMaterialCost.getPrice()));
                        partPrice.setTotalPrice(Objects.isNull(plasticMaterialCost.getTotalPrice()) ? "" : String.valueOf(plasticMaterialCost.getTotalPrice()));
                        partPrice.setType("2");
                        partPriceService.save(partPrice);
                    }
                    //试模费用
                    if (null != tryoutFee) {
                        PartPrice partPrice = new PartPrice();
                        partPrice.setId(IdUtils.simpleUUID());
                        partPrice.setMoldId(moldId);
                        partPrice.setPartId(tryoutFee.getDeviceId());
                        partPrice.setPartName(InnerOtherEnum.SIX.getName());
                        partPrice.setNum(Objects.isNull(tryoutFee.getHour()) ? "" : String.valueOf(tryoutFee.getHour()));
                        partPrice.setPrice(Objects.isNull(tryoutFee.getPrice()) ? "" : String.valueOf(tryoutFee.getPrice()));
                        partPrice.setTotalPrice(Objects.isNull(tryoutFee.getTotalPrice()) ? "" : String.valueOf(tryoutFee.getTotalPrice()));
                        partPrice.setType("2");
                        partPriceService.save(partPrice);
                    }

                }
                return JSON.toJSONString(R.success("保存成功"));
            }
        } catch (RuntimeException e) {
            log.error("保存内部报价单时失败:{}", e.toString(), e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JSON.toJSONString(R.fail(e.getMessage()));
        } catch (Exception e) {
            log.error("保存内部报价单时失败:{}", e.toString(), e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JSON.toJSONString(R.fail("保存失败"));
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    /**
     * 保存内部报价主表 t_inner_quotation表
     *
     * @param moldSelectionId
     * @param detailsVO
     */
    private void saveInnerQuotation(String moldSelectionId, ReqInnerQuoDetailsVO detailsVO) {
        InnerQuotation innerQuotation = new InnerQuotation();
        //保存内部报价主表 t_inner_quotation表
        innerQuotation.setId(IdUtils.simpleUUID());
        innerQuotation.setMoldSelectionId(moldSelectionId);
        //计算总计
        BigDecimal totalMainMaterialFee = new BigDecimal(0.00);
        BigDecimal totalMouldFee = new BigDecimal(0.00);
        BigDecimal totalIronMaterialFee = new BigDecimal(0.00);
        BigDecimal totalStandardComponentFee = new BigDecimal(0.00);
        BigDecimal totalOutsourceFee = new BigDecimal(0.00);
        BigDecimal totalHotRunnerFee = new BigDecimal(0.00);
        BigDecimal totalBoughtInComponents = new BigDecimal(0.00);
        BigDecimal totalTextureFee = new BigDecimal(0.00);
        BigDecimal totalPlasticFee = new BigDecimal(0.00);
        BigDecimal totalAssemblyFee = new BigDecimal(0.00);
        BigDecimal totalTryoutFee = new BigDecimal(0.00);
        BigDecimal totalTransportFee = new BigDecimal(0.00);
        BigDecimal totalManufacturingFee = new BigDecimal(0.00);
        BigDecimal totalPeriodFee = new BigDecimal(0.00);
        BigDecimal totalPriceWithoutTax = new BigDecimal(0.00);
        BigDecimal totalGrossProfit = new BigDecimal(0.00);
        for (InnerBaseInfo innerBaseInfo : detailsVO.getDataList()) {
            totalMainMaterialFee = totalMainMaterialFee.add(new BigDecimal(innerBaseInfo.getMainMaterialsFee()));
            totalMouldFee = totalMouldFee.add(new BigDecimal(innerBaseInfo.getMouldFee()));
            totalIronMaterialFee = totalIronMaterialFee.add(new BigDecimal(innerBaseInfo.getIronMaterialsFee()));
            totalStandardComponentFee = totalStandardComponentFee.add(new BigDecimal(innerBaseInfo.getStandardComponentFee()));
            totalOutsourceFee = totalOutsourceFee.add(new BigDecimal(innerBaseInfo.getOutsourceFee()));
            totalHotRunnerFee = totalHotRunnerFee.add(new BigDecimal(innerBaseInfo.getHotRunnerAimFee()));
            totalBoughtInComponents = totalBoughtInComponents.add(new BigDecimal(innerBaseInfo.getBoughtInComponents()));
            totalTextureFee = totalTextureFee.add(new BigDecimal(innerBaseInfo.getTexturingAimFee()));
            totalPlasticFee = totalPlasticFee.add(new BigDecimal(innerBaseInfo.getPlasticMaterialAimFee()));
            totalAssemblyFee = totalAssemblyFee.add(new BigDecimal(innerBaseInfo.getAssemblyFee()));
            totalTryoutFee = totalTryoutFee.add(new BigDecimal(innerBaseInfo.getTryoutFee()));
            totalTransportFee = totalTransportFee.add(new BigDecimal(innerBaseInfo.getTransportFee()));
            totalManufacturingFee = totalManufacturingFee.add(new BigDecimal(innerBaseInfo.getManufacturingFee()));
            totalPeriodFee = totalPeriodFee.add(new BigDecimal(innerBaseInfo.getPeriodRectificationFee()));
            totalPriceWithoutTax = totalPriceWithoutTax.add(new BigDecimal(innerBaseInfo.getFinalTaxNotIncluded()));
            totalGrossProfit = totalGrossProfit.add(new BigDecimal(innerBaseInfo.getTargetGrossProfit()));

        }
        //保留位数
        int newScale = 2;
        //AB板及主材 所有详情的累计
        innerQuotation.setMainMaterialFee(totalMainMaterialFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //模架:表示价格 = 分表中模架总价，自动计算
        innerQuotation.setMouldFee(totalMouldFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //小钢料
        innerQuotation.setIronMaterialFee(totalIronMaterialFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //标准件
        innerQuotation.setStandardComponentFee(totalStandardComponentFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //制造加工成本目标价
        innerQuotation.setOutsourceFee(totalOutsourceFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //热流道目标价
        innerQuotation.setHotRunnerFee(totalHotRunnerFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //外购件（包含电极和检具）
        innerQuotation.setBoughtInComponents(totalBoughtInComponents.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //纹理费用目标价
        innerQuotation.setTextureFee(totalTextureFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //塑胶材料目标价
        innerQuotation.setPlasticFee(totalPlasticFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //装配费用
        innerQuotation.setAssemblyFee(totalAssemblyFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //试模费用
        innerQuotation.setTryoutFee(totalTryoutFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //运输费
        innerQuotation.setTransportFee(totalTransportFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //制造费用
        innerQuotation.setManufacturingFee(totalManufacturingFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //期间整改费用
        innerQuotation.setPeriodFee(totalPeriodFee.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //最终未含税
        innerQuotation.setPriceWithoutTax(totalPriceWithoutTax.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //目标毛利润
        innerQuotation.setGrossProfit(totalGrossProfit.setScale(newScale, BigDecimal.ROUND_HALF_UP).toPlainString());
        //最终工序目标毛利润占比
        innerQuotation.setGrossProfitRatio(detailsVO.getTotalFeeOfAll().getPercentageOfFinalProcessTargetGrossProfitTotal());
        //编制
        innerQuotation.setMaker("");
        //审核
        innerQuotation.setAuditor("");
        //批准
        innerQuotation.setApprover("");
        // 0：未提交 1：已提交
        innerQuotation.setStatus("0");
        //保存或修改
        innerQuotationService.saveOrUpdate(innerQuotation);
    }

    /**
     * 保存t_part_price表
     *
     * @param moldId
     * @param num
     * @param price
     * @param totalPrice
     * @param partName
     */
    private void savePartPrice(String moldId, String num, Double price, Double totalPrice, Double standardComponentFee, String partName) {
        PartPrice partPrice = new PartPrice();
        partPrice.setId(IdUtils.simpleUUID());
        partPrice.setMoldId(moldId);
        partPrice.setPartName(partName);
        partPrice.setNum(num);
        partPrice.setPrice(Objects.isNull(price) ? "" : String.valueOf(price));
        partPrice.setTotalPrice(Objects.isNull(totalPrice) ? "" : String.valueOf(totalPrice));
        partPrice.setStandardComponentFee(Objects.isNull(standardComponentFee) ? "" : String.valueOf(standardComponentFee));
        partPrice.setType("2");
        partPriceService.save(partPrice);
    }

    private void savePartPriceBatch(List<PartPrice> partPrices) {
        partPriceService.saveOrUpdateBatch(partPrices);
    }


    @Override
    public String postInnerQuotationToCheck(JSONObject jsonObject) {
        //jsonobject解析获取申请提交或者撤回
        String isPostToCheck = jsonObject.getString("isPostToCheck");
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");

        if (StringUtils.isEmpty(moldSelectionId)) {
            return JSONObject.toJSONString(R.fail("参数错误,选模表Id 不能为空"));
        }
        InnerQuotation innerQuotation = innerQuotationService.getOne(new LambdaQueryWrapper<InnerQuotation>().eq(InnerQuotation::getMoldSelectionId, moldSelectionId));
        if ("true".equals(isPostToCheck)) {
            innerQuotation.setStatus("1");
            innerQuotationService.updateById(innerQuotation);
            JSONObject resultJson = new JSONObject();
            resultJson.put("moldSelectionId", moldSelectionId);
            resultJson.put("status", "1");
            //向OA系统发送内部报价单
            innerQuotationToCheckSendOA(innerQuotation);
            return JSONObject.toJSONString(R.data(resultJson, "提交成功"));
        }
        if ("false".equals(isPostToCheck)) {
            innerQuotation.setStatus("0");
            innerQuotationService.updateById(innerQuotation);
            JSONObject resultJson = new JSONObject();
            resultJson.put("moldSelectionId", moldSelectionId);
            resultJson.put("status", "0");
            return JSONObject.toJSONString(R.data(resultJson, "撤回成功"));
        }

        return JSON.toJSONString(R.success("无数据"));
    }

    private void innerQuotationToCheckSendOA(InnerQuotation innerQuotation) {
        try {
            HttpResponse login = ApiUtilServiceImpl.login(keyWord.getApi());
            if (login.getStatus() == org.springframework.http.HttpStatus.OK.value()) {
                List<InnerQuotationDetail> quotationDetailList = iInnerQuotationDetailService.list(new LambdaQueryWrapper<InnerQuotationDetail>()
                        .eq(InnerQuotationDetail::getMoldSelectionId, innerQuotation.getMoldSelectionId())
                        .orderByAsc(InnerQuotationDetail::getMoldId));
                if (Objects.nonNull(quotationDetailList) && !quotationDetailList.isEmpty()) {
                    List<InnerQuotationApi> innerQuotationApiList = quotationDetailList.parallelStream().map(detail -> {
                        InnerQuotationApi innerQuotationApi = InnerQuotationApi.builder()
                                .mouldName(detail.getProductName())
                                .mouldNumber(detail.getMoldId())
                                .productSize(detail.getProductSize())
                                .moldMaterial(detail.getPour())
                                .cavityCount(detail.getCavityNum())
                                .abPlateAndMainMaterialCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getMainMaterialFee()))
                                .mouldFrameCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getMouldFee()))
                                .smallSteelComponentCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getIronMaterialFee()))
                                .standardPartsCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getStandardComponentFee()))
                                .manufacturingCostTargetCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getOutsourceFee()))
                                .hotRunnerTargetCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getHotRunnerFee()))
                                .purchasedPartsTargetCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getBoughtInComponents()))
                                .textureCostTargetCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getTextureFee()))
                                .plasticMaterialsTargetCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getPlasticFee()))
                                .assemblingCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getAssemblyFee()))
                                .mouldTestingCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getTryoutFee()))
                                .transportationCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getTransportFee()))
                                .manufacturingCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getManufacturingFee()))
                                .rectificationCost(BigdecimalUtil.stringTo2DecimalDouble(detail.getPeriodFee()))
                                .finalCostExcludingTax(BigdecimalUtil.stringTo2DecimalDouble(detail.getPriceWithoutTax()))
                                .targetGrossProfit(BigdecimalUtil.stringTo2DecimalDouble(detail.getGrossProfit()))
                                .mouldTestingTimes(StringUtils.isNotBlank(detail.getTryoutTimes()) ? Integer.valueOf(detail.getTryoutTimes()) : 0)
                                .build();
                        return innerQuotationApi;
                    }).collect(Collectors.toList());

                    JSONObject json = new JSONObject();
                    json.put("moulds", innerQuotationApiList);
                    log.info("向OA系统发送内部报价单:{}", json.toJSONString());
                    HttpResponse httpResponse = ApiUtilServiceImpl.
                            doPost(keyWord.getApi() + ApiUtilServiceImpl.CREATE_INNERQUOTATION, json, login.body());
                    log.info("向OA系统发送内部报价单,返回状态：{}", httpResponse.getStatus());
                    log.info("向OA系统发送内部报价单,返回参数：{}", httpResponse.body());
                } else {
                    log.info("向OA系统发送内部报价单时数据为空,选模id:{}", innerQuotation.getMoldSelectionId());
                }
            } else {
                log.info("向OA系统发送内部报价单时系统未登录......");
            }
        } catch (Exception e) {
            log.error("推送内部报价单,选模id:{}至OA系统失败:{}", innerQuotation.getMoldSelectionId(), e.toString(), e);
        }
    }


    @Override
    public String deleteInnerQuotationSubTableById(JSONObject jsonObject) {
        String moldSelectionId = null;
        String subTableId = null;
        try {
            //jsonobject解析获取选模表Id
            moldSelectionId = jsonObject.getString("moldSelectionId");
            //jsonobject解析获取分表Id
            subTableId = jsonObject.getString("subTableId");

            InnerQuotationDetail one = iInnerQuotationDetailService.getOne(new LambdaQueryWrapper<InnerQuotationDetail>()
                    .eq(InnerQuotationDetail::getMoldSelectionId, moldSelectionId).eq(InnerQuotationDetail::getId, subTableId));
            if (null != one) {
                partPriceService.remove(new LambdaQueryWrapper<PartPrice>().eq(PartPrice::getMoldId, one.getMoldId()));
                iInnerQuotationPartPriceService.remove(new LambdaQueryWrapper<InnerQuotationPartPrice>().eq(InnerQuotationPartPrice::getMoldId, one.getMoldId()));
                iInnerQuotationDetailService.remove(new LambdaQueryWrapper<InnerQuotationDetail>().eq(InnerQuotationDetail::getId, subTableId));
            }
        } catch (Exception e) {
            return JSON.toJSONString(R.fail("删除失败"));
        }

        return JSON.toJSONString(R.success("删除成功"));

    }

    @Transactional
    @Override
    public String deleteOutQuotationSubTableById(JSONObject jsonObject) {
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        //jsonobject解析获取分表Id
        String subTableId = jsonObject.getString("subTableId");
        String mainEnginePlantId = jsonObject.getString("mainEnginePlantId");
        if (StringUtils.isEmpty(moldSelectionId)) {
            return JSON.toJSONString(R.fail("参数错误，选模表Id不能为空"));
        }
        if (StringUtils.isEmpty(subTableId)) {
            return JSON.toJSONString(R.fail("参数错误，分表Id不能为空"));
        }
        if (StringUtils.isEmpty(mainEnginePlantId)) {
            return JSON.toJSONString(R.fail("参数错误，客户方Id不能为空"));
        }
        String mainEnginePlantName = "";
        try {
            for (MainEnginePlantEnum value : MainEnginePlantEnum.values()) {
                String code = value.getCode();
                if (mainEnginePlantId.equals(code)) {
                    mainEnginePlantName = value.getName();
                }
            }
            //验证客户方在枚举中是否存在
            if (StringUtils.isEmpty(mainEnginePlantName)) {
                return JSON.toJSONString(R.fail("当前客户不存在，请联系管理员！"));
            }

            if (mainEnginePlantId.equals(MainEnginePlantEnum.ONE.getCode())) {
                //根据分表id查询出主表的id
                CommonQuotationDetail detail = commonQuotationDetailService.getOne(new QueryWrapper<CommonQuotationDetail>().lambda().eq(CommonQuotationDetail::getId, subTableId));
                if (detail != null) {
                    //根据主表id查询出(排除删除后的数据),方便为主表重新计算费用
                    String quotationId = detail.getCommonQuotationId();
                    List<CommonQuotationDetail> list = commonQuotationDetailService.list(new QueryWrapper<CommonQuotationDetail>().lambda()
                            .ne(CommonQuotationDetail::getId, subTableId)
                            .eq(CommonQuotationDetail::getCommonQuotationId, quotationId));
                    //求和统计
                    double textureFee = list.stream().map(param -> param.getTextureFee()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double moldFee = list.stream().map(param -> param.getMoldFee()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double priceWithoutTax = list.stream().map(param -> param.getPriceWithoutTax()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    CommonQuotation one = commonQuotationMapper.selectOne(new QueryWrapper<CommonQuotation>().lambda().eq(CommonQuotation::getMoldSelectionId, moldSelectionId));
                    if (null != one) {
                        one.setTextureFee(String.valueOf(textureFee));
                        one.setMoldFee(String.valueOf(moldFee));
                        one.setPriceWithoutTax(String.valueOf(priceWithoutTax));
                        commonQuotationMapper.updateById(one);
                    }
                    commonQuotationDetailService.remove(new QueryWrapper<CommonQuotationDetail>().lambda().eq(CommonQuotationDetail::getId, subTableId));
                    commonQuotationPriceService.remove(new QueryWrapper<CommonQuotationPrice>().lambda()
                            .eq(CommonQuotationPrice::getDetailId, subTableId)
                            .eq(CommonQuotationPrice::getMoldSelectionId, moldSelectionId));
                }
            }
            if (mainEnginePlantId.equals(MainEnginePlantEnum.TWO.getCode())) {
                //根据分表id查询出主表的id
                DfQuotationDetail detail = dfQuotationDetailService.getOne(new QueryWrapper<DfQuotationDetail>().lambda().eq(DfQuotationDetail::getId, subTableId));
                if (detail != null) {
                    //根据主表id查询出(排除删除后的数据),方便为主表重新计算费用
                    String quotationId = detail.getQuotationId();
                    List<DfQuotationDetail> list = dfQuotationDetailService.list(new QueryWrapper<DfQuotationDetail>().lambda()
                            .ne(DfQuotationDetail::getId, subTableId)
                            .eq(DfQuotationDetail::getQuotationId, quotationId));
                    //求和统计
                    double moldFee = list.stream().map(param -> param.getMoldFee()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double moldTotalFee = list.stream().map(param -> param.getMoldTotalFee()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();

                    DfQuotation one = dfQuotationService.getOne(new QueryWrapper<DfQuotation>().lambda().eq(DfQuotation::getMoldSelectionId, moldSelectionId));
                    if (null != one) {
                        one.setMoldFee(String.valueOf(moldFee));
                        one.setMoldTotalFee(String.valueOf(moldTotalFee));
                        dfQuotationService.updateById(one);
                    }
                    dfQuotationDetailService.remove(new QueryWrapper<DfQuotationDetail>().lambda().eq(DfQuotationDetail::getId, subTableId));
                    dfQuotationPriceService.remove(new QueryWrapper<DfQuotationPrice>().lambda()
                            .eq(DfQuotationPrice::getDetailId, subTableId)
                            .eq(DfQuotationPrice::getMoldSelectionId, moldSelectionId));
                }
            }
            if (mainEnginePlantId.equals(MainEnginePlantEnum.THREE.getCode())) {
                //根据分表id查询出主表的id
                List<JlQuotationDetail> list = jlQuotationDetailService.list(new QueryWrapper<JlQuotationDetail>().lambda().eq(JlQuotationDetail::getMoldSelectionId, moldSelectionId));
                List<JlQuotationDetail> handerList = Lists.newArrayList();
                for (JlQuotationDetail jlQuotationDetail : list) {
                    //根据主表id查询出(排除删除后的数据),方便为主表重新计算费用
                    if (!subTableId.equals(jlQuotationDetail.getId())) {
                        handerList.add(jlQuotationDetail);
                    }
                }
                if (null != handerList) {
                    //求和统计
                    double moldFee = handerList.stream().map(param -> param.getProfit()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double moldTotalFee = handerList.stream().map(param -> param.getMoldTotalFee()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    JlQuotation one = jlQuotationService.getOne(new QueryWrapper<JlQuotation>().lambda().eq(JlQuotation::getMoldSelectionId, moldSelectionId));
                    if (null != one) {
                        one.setProfit(String.valueOf(moldFee));
                        one.setMoldTotalFee(String.valueOf(moldTotalFee));
                        jlQuotationService.updateById(one);
                    }
                }
                jlQuotationDetailService.remove(new QueryWrapper<JlQuotationDetail>().lambda().eq(JlQuotationDetail::getId, subTableId));
                jlQuotationPriceService.remove(new QueryWrapper<JlQuotationPrice>().lambda()
                        .eq(JlQuotationPrice::getDetailId, subTableId).eq(JlQuotationPrice::getMoldSelectionId, moldSelectionId));

            }
            if (mainEnginePlantId.equals(MainEnginePlantEnum.FOUR.getCode())) {
                //根据分表id查询出主表的id
                List<QrQuotationDetail> list = iQrQuotationDetailService.list(new QueryWrapper<QrQuotationDetail>().lambda().eq(QrQuotationDetail::getMoldSelectionId, moldSelectionId));
                List<QrQuotationDetail> handerList = Lists.newArrayList();
                for (QrQuotationDetail qrQuotationDetail : list) {
                    //根据主表id查询出(排除删除后的数据),方便为主表重新计算费用
                    if (!subTableId.equals(qrQuotationDetail.getId())) {
                        handerList.add(qrQuotationDetail);
                    }
                }
                if (null != handerList) {
                    //求和统计
                    double machiningMaterialCost = handerList.stream().map(param -> param.getMachiningMaterialCost()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double heatTreatment = handerList.stream().map(param -> param.getHeatTreatment()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double assemlyMaterialCost = handerList.stream().map(param -> param.getAssemlyMaterialCost()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double designCost = handerList.stream().map(param -> param.getDesignCost()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double manufacturingCost = handerList.stream().map(param -> param.getManufacturingCost()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double cmmMeasure = handerList.stream().map(param -> param.getCmmMeasure()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double moldFee = handerList.stream().map(param -> param.getMoldTotalFee()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double profit = handerList.stream().map(param -> param.getProfit()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double tryoutFee = handerList.stream().map(param -> param.getTryoutFee()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double transportFee = handerList.stream().map(param -> param.getTransportFee()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();

                    QrQuotation one = iQrQuotationService.getOne(new QueryWrapper<QrQuotation>().lambda().eq(QrQuotation::getMoldSelectionId, moldSelectionId));
                    if (null != one) {
                        one.setMachiningMaterialCost(String.valueOf(machiningMaterialCost));
                        one.setHeatTreatment(String.valueOf(heatTreatment));
                        one.setAssemlyMaterialCost(String.valueOf(assemlyMaterialCost));
                        one.setDesignCost(String.valueOf(designCost));
                        one.setManufacturingCost(String.valueOf(manufacturingCost));
                        one.setCmmMeasure(String.valueOf(cmmMeasure));
                        one.setManagementFee(String.valueOf(moldFee));
                        one.setProfit(String.valueOf(profit));
                        one.setTryoutFee(String.valueOf(tryoutFee));
                        one.setTransportFee(String.valueOf(transportFee));
                        iQrQuotationService.updateById(one);
                    }
                }
                iQrQuotationDetailService.remove(new QueryWrapper<QrQuotationDetail>().lambda().eq(QrQuotationDetail::getId, subTableId));
                iQrQuotationPriceService.remove(new QueryWrapper<QrQuotationPrice>().lambda()
                        .eq(QrQuotationPrice::getDetailId, subTableId).eq(QrQuotationPrice::getMoldSelectionId, moldSelectionId));
            }
            if (mainEnginePlantId.equals(MainEnginePlantEnum.FIVE.getCode())) {
                //根据分表id查询出主表的id
                List<BydQuotationDetail> list = iBydQuotationDetailService.list(new QueryWrapper<BydQuotationDetail>().lambda().eq(BydQuotationDetail::getQuotationId, subTableId));
                List<BydQuotationDetail> handerList = Lists.newArrayList();
                for (BydQuotationDetail qrQuotationDetail : list) {
                    //根据主表id查询出(排除删除后的数据),方便为主表重新计算费用
                    if (!subTableId.equals(qrQuotationDetail.getId())) {
                        handerList.add(qrQuotationDetail);
                    }
                }
                if (null != handerList) {
                    //求和统计
                    double checkingFixtureFee = handerList.stream().map(param -> param.getCheckingFixtureFee()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();
                    double priceWithoutTax = handerList.stream().map(param -> param.getPriceWithoutTax()).filter(a -> a != null).mapToDouble(Double::parseDouble).sum();

                    BydQuotation one = iBydQuotationService.getOne(new QueryWrapper<BydQuotation>().lambda().eq(BydQuotation::getMoldSelectionId, moldSelectionId));
                    if (null != one) {
                        one.setCheckingFixtureFee(String.valueOf(checkingFixtureFee));
                        one.setPriceWithoutTax(String.valueOf(priceWithoutTax));
                        iBydQuotationService.updateById(one);
                    }
                }
                iBydQuotationDetailService.remove(new QueryWrapper<BydQuotationDetail>().lambda().eq(BydQuotationDetail::getId, subTableId));
                iBydQuotationPriceService.remove(new QueryWrapper<BydQuotationPrice>().lambda()
                        .eq(BydQuotationPrice::getDetailId, subTableId)
                        .eq(BydQuotationPrice::getMoldSelectionId, moldSelectionId));
            }
        } catch (RuntimeException e) {
            log.error("删除外部报价单分表失败:{}", e.toString(), e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JSON.toJSONString(R.fail(e.getMessage()));
        } catch (Exception e) {
            log.error("删除外部报价单分表失败:{}", e.toString(), e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JSON.toJSONString(R.fail("删除失败"));
        }
        return JSON.toJSONString(R.success("删除成功"));
    }

    @Override
    public String deleteNormalOutQuotationSubTableById(JSONObject jsonObject) {
        //jsonobject解析获取分表Id
        String subTableId = jsonObject.getString("subTableId");
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        if (
                "1".equals(subTableId)
                        &&
                        "1".equals(moldSelectionId)
        ) {
            return "{\"msg\":\"删除成功\",\"data\":{},\"success\":true}";
        }
        if (
                "1".equals(moldSelectionId)
        ) {
            return "{\"msg\":\"参数错误，选模表Id不能为空\",\"code\":400,\"success\":false}";
        }
        if (
                "1".equals(moldSelectionId)
        ) {
            return "{\"msg\":\"参数错误，分表Id不能为空\",\"code\":400,\"success\":false}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String saveDFOutQuotation(JSONObject jsonObject) {
        //开启事务
        TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
        try {
            //jsonobject解析获取选模表Id
            String moldSelectionId = jsonObject.getString("moldSelectionId");
            //封装数据
            DfQuotationVo dfQuotationVo = JSONObject.parseObject(jsonObject.toJSONString(), DfQuotationVo.class);

            //验证数据是否有效合法
            checkQuotationDataService.checkDfData(dfQuotationVo);

            //1、查询主表数据是否存在
            DfQuotation oldDfQuotation = dfQuotationService.getOne(new LambdaQueryWrapper<DfQuotation>().eq(DfQuotation::getMoldSelectionId, moldSelectionId));
            //主表id
            String quotationId = "";
            if (null != oldDfQuotation) {
                quotationId = oldDfQuotation.getId();
            } else {
                quotationId = IdUtils.simpleUUID();
            }
            //2、保存数据至主表
            DfQuotation dfQuotation = new DfQuotation();
            if (StringUtils.isEmpty(dfQuotation.getId())) {
                dfQuotation.setId(quotationId);
            }
            dfQuotation.setMoldSelectionId(dfQuotationVo.getMoldSelectionId());
            dfQuotation.setProjectName(dfQuotationVo.getProjectName());
            dfQuotation.setUnit(dfQuotationVo.getUnit());
            dfQuotation.setAddress(dfQuotationVo.getAddress());
            dfQuotation.setZip(dfQuotationVo.getZIP());
            dfQuotation.setTel(dfQuotationVo.getTEL());
            dfQuotation.setFax(dfQuotationVo.getFAX());
            dfQuotation.setEmail(dfQuotationVo.getEMail());
            dfQuotation.setTel(dfQuotationVo.getTEL());
            dfQuotation.setWebsite(dfQuotationVo.getWebsite());
            dfQuotation.setFrom(dfQuotationVo.getFrom());
            dfQuotation.setTo(dfQuotationVo.getTo());
            dfQuotation.setContact(dfQuotationVo.getContactName());
            dfQuotation.setPhone(dfQuotationVo.getContactPhone());

            dfQuotation.setMoldFee(dfQuotationVo.getMouldFeeTotal());
            dfQuotation.setMoldTotalFee(String.valueOf(dfQuotationVo.getPriceWithoutTaxIncludesSkinGrainTotal()));

            dfQuotation.setMaker(dfQuotationVo.getQuotedPrice());
            dfQuotation.setAuditor(dfQuotationVo.getCheckoutName());
            dfQuotation.setApprover(dfQuotationVo.getApprover());
            dfQuotation.setDate(LocalDate.now());
            dfQuotation.setTextureFee(String.valueOf(dfQuotationVo.getTextureFeeTotal()));
            dfQuotationService.saveOrUpdate(dfQuotation);

            //3、保存详情表,先删除旧数据 后保存
            List<String> subTableIds = Lists.newArrayList();
            if (!CollectionUtils.isEmpty(dfQuotationVo.getDataList())) {
                for (DfObject dfObject : dfQuotationVo.getDataList()) {
                    subTableIds.add(dfObject.getSubTableId());
                }
            }
            if (!CollectionUtils.isEmpty(subTableIds)) {
                QueryWrapper<DfQuotationDetail> queryWrapper = new QueryWrapper<>();
                queryWrapper.in("id", subTableIds);
                dfQuotationDetailService.remove(queryWrapper);
                //清除分表数据
                QueryWrapper<DfQuotationPrice> queryWrapperPrice = new QueryWrapper<>();
                queryWrapper.eq("mold_selection_id", moldSelectionId);
                queryWrapper.in("detail_id", subTableIds);
                dfQuotationPriceService.remove(queryWrapperPrice);
            }


            for (DfObject df : dfQuotationVo.getDataList()) {
                DfQuotationDetail detail = new DfQuotationDetail();
                String detailId = IdUtils.simpleUUID();
                detail.setId(detailId);
                //主表id
                detail.setQuotationId(dfQuotation.getId());

                detail.setProductName(df.getNameOfProduct());
                detail.setProductCode(df.getCodeOfProduct());
                detail.setProductImage(df.getImageOfProduct());
                //材料信息
                detail.setProductMaterial(df.getMaterials());

                detail.setCavityNum(df.getCavityCount());
                detail.setCavity(df.getMaterialOfCavity());
                detail.setPour(df.getPourSystem());
                detail.setCore(df.getMaterialOfCore());
                detail.setMoldBaseMaterial(df.getMouldIronMaterial());

                DfDetailData dfDetailData = df.getDetailData();

                detail.setProductSize(dfDetailData.getLengthOfProduct() + "*" + dfDetailData.getWidthOfProduct() + "*" + dfDetailData.getHeightOfProduct());
                detail.setProductLength(String.valueOf(dfDetailData.getLengthOfProduct()));
                detail.setProductWidth(String.valueOf(dfDetailData.getWidthOfProduct()));
                detail.setProductHeight(String.valueOf(dfDetailData.getHeightOfProduct()));

                //运动件
                detail.setMovingParts(df.getMovingParts());
                //模具尺寸
                detail.setMoldSize(dfDetailData.getLengthOfShape() + "*" + dfDetailData.getWidthOfShape() + "*" + dfDetailData.getHeightOfShape());
                //模具尺寸-长
                detail.setMoldLength(String.valueOf(dfDetailData.getLengthOfShape()));
                //模具尺寸-宽
                detail.setMoldWidth(String.valueOf(dfDetailData.getWidthOfShape()));
                //模具尺寸-高
                detail.setMoldHeight(String.valueOf(dfDetailData.getHeightOfShape()));
                //试模设备Id = 注塑设备Id
                detail.setDeviceId(df.getDeviceId());
                if (StringUtils.isNotBlank(df.getDeviceId())) {
                    TryOutDeviceMod tryOutDeviceMod = tryOutDeviceModService.getById(df.getDeviceId());
                    if (null != tryOutDeviceMod) {
                        detail.setDeviceName(tryOutDeviceMod.getDeviceName());
                    }
                }

                //模具寿命
                detail.setMoldLongevity(dfDetailData.getLongevity());
                detail.setLongevity(df.getLifetime());
                //注塑机吨位
                detail.setPress(dfDetailData.getPressTon());
                detail.setPhone(dfDetailData.getPhone());
                detail.setMoldName(dfDetailData.getMoldName());
                detail.sett1Time(dfDetailData.getT0Time());
                //产品重量
                detail.setProductWeight(String.valueOf(dfDetailData.getWeightOfProduct()));
                detail.setDrawing(dfDetailData.getDrawingNo());
                detail.setLeadTime(dfDetailData.getLeadTime());
                detail.setMoldWeight(String.valueOf(dfDetailData.getMoldWeight()));

                detail.setContacts(dfDetailData.getContacts());
                detail.setMoldName(dfDetailData.getMoldName());
                detail.setMoldWeight(String.valueOf(dfDetailData.getMoldWeight()));

                if (Objects.nonNull(dfDetailData.getMachiningMaterialCost())) {
                    detail.setMachiningMaterialCost(String.valueOf(dfDetailData.getMachiningMaterialCost().getSubTotal()));
                }
                if (Objects.nonNull(dfDetailData.getHeatTreatmentCost())) {
                    detail.setHeatTreatment(String.valueOf(dfDetailData.getHeatTreatmentCost().getSubTotal()));
                }
                if (Objects.nonNull(dfDetailData.getAssemlyMaterialCost())) {
                    detail.setAssemlyMaterialCost(String.valueOf(dfDetailData.getAssemlyMaterialCost().getSubTotal()));
                }
                if (null != dfDetailData.getDesignCost()) {
                    detail.setDesignCost(String.valueOf(dfDetailData.getDesignCost().getSubTotal()));
                } else {
                    detail.setDesignCost(null);
                }
                if (null != dfDetailData.getManufacturingCost()) {
                    detail.setManufacturingCost(String.valueOf(dfDetailData.getManufacturingCost().getSubTotal()));
                }
                if (null != dfDetailData.getCMMMeasure()) {
                    detail.setCmmMeasure(String.valueOf(dfDetailData.getCMMMeasure().getSubTotal()));
                }
                if (null != dfDetailData.getOtherFee()) {
                    detail.setOtherFee(String.valueOf(dfDetailData.getOtherFee().getSubTotal()));
                }

                detail.setMoldFee(String.valueOf(df.getMouldFee()));
                detail.setMoldTotalFee(String.valueOf(df.getMouldTotalFee()));
                detail.setTextureFee(String.valueOf(df.getTextureFee()));
                detail.setTotalFee(String.valueOf(dfDetailData.getTotalPrice()));


                detail.setMakeTime(df.getProductionCycle());
                detail.setRemark(df.getRemark());


                detail.setSupplier(dfDetailData.getSupplier());
                detail.setDate(dfDetailData.getDate());
                detail.setSignature(dfDetailData.getSignature());
                detail.setStamp(dfDetailData.getStamp());
                if (null != dfDetailData.getMachiningMaterialCost()) {
                    detail.setMachiningMaterialCost(String.valueOf(dfDetailData.getMachiningMaterialCost().getSubTotal()));
                }
                if (null != dfDetailData.getHeatTreatmentCost()) {
                    detail.setHeatTreatment(String.valueOf(dfDetailData.getHeatTreatmentCost().getSubTotal()));
                }
                if (null != dfDetailData.getAssemlyMaterialCost()) {
                    detail.setAssemlyMaterialCost(String.valueOf(dfDetailData.getAssemlyMaterialCost().getSubTotal()));
                }
                if (null != dfDetailData.getDesignCost()) {
                    detail.setDesignCost(String.valueOf(dfDetailData.getDesignCost().getSubTotal()));
                }
                if (null != dfDetailData.getManufacturingCost()) {
                    detail.setManufacturingCost(String.valueOf(dfDetailData.getManufacturingCost().getSubTotal()));
                }
                if (null != dfDetailData.getCMMMeasure()) {
                    detail.setCmmMeasure(String.valueOf(dfDetailData.getCMMMeasure().getSubTotal()));
                }
                if (null != dfDetailData.getOtherFee()) {
                    detail.setOtherFee(String.valueOf(dfDetailData.getOtherFee().getSubTotal()));
                }

                detail.setSurface(df.getSurface());
                detail.setHydroCylinder(String.valueOf(df.getHydroCylinder()));
                detail.setEyeBolt(String.valueOf(df.getEyeBolt()));
                dfQuotationDetailService.saveOrUpdate(detail);

                //保存分表
                DfDetailData detailData = dfDetailData;
                DfQuotationPrice price = null;

                String type = NormalOutQuotationaSubEnum.MACHINING_MATERIAL_COST.getCn();
                List<DfQuotationPrice> insertMaching = Lists.newArrayList();
                if (null != detailData.getMachiningMaterialCost()) {
                    for (ItemMach itemMach : detailData.getMachiningMaterialCost().getDataList()) {
                        price = new DfQuotationPrice();
                        price.setMoldSelectionId(moldSelectionId);
                        price.setDetailId(detail.getId());
                        price.setType(type);
                        price.setName(itemMach.getItemName());
                        price.setLength(String.valueOf(itemMach.getLength()));
                        price.setWidth(String.valueOf(itemMach.getWidth()));
                        price.setHeight(String.valueOf(itemMach.getHeight()));
                        price.setNum(String.valueOf(itemMach.getWeight()));
                        price.setPrice(String.valueOf(itemMach.getPrice()));
                        price.setSpecification(itemMach.getSpecification());
                        price.setTotalPrice(String.valueOf(itemMach.getTotalPrice()));
                        insertMaching.add(price);
                    }
                    dfQuotationPriceService.saveBatch(insertMaching);
                }

                type = NormalOutQuotationaSubEnum.HEAT_TREATMENT.getCn();
                List<DfQuotationPrice> insertHeat = Lists.newArrayList();
                if (null != detailData.getHeatTreatmentCost()) {
                    for (ItemHeat itemHeat : detailData.getHeatTreatmentCost().getDataList()) {
                        price = new DfQuotationPrice();
                        price.setMoldSelectionId(moldSelectionId);
                        price.setDetailId(detail.getId());
                        price.setType(type);
                        price.setName(itemHeat.getItemName());
                        price.setNum(String.valueOf(itemHeat.getWeight()));
                        price.setPrice(String.valueOf(itemHeat.getPrice()));
                        price.setTotalPrice(String.valueOf(itemHeat.getTotalPrice()));
                        insertHeat.add(price);
                    }
                    dfQuotationPriceService.saveBatch(insertHeat);
                }


                type = NormalOutQuotationaSubEnum.ASSEMLY_MATERIAL_COST.getCn();
                List<DfQuotationPrice> insertAssemly = Lists.newArrayList();
                if (null != detailData.getAssemlyMaterialCost()) {
                    for (ItemAssemly itemAssemly : detailData.getAssemlyMaterialCost().getDataList()) {
                        price = new DfQuotationPrice();
                        price.setMoldSelectionId(moldSelectionId);
                        price.setDetailId(detail.getId());
                        price.setType(type);
                        price.setName(itemAssemly.getItemName());
                        price.setNum(String.valueOf(itemAssemly.getCount()));
                        price.setSpecification(itemAssemly.getSpecification());
                        price.setSupplier(itemAssemly.getSupplier());
                        price.setPrice(String.valueOf(itemAssemly.getPrice()));
                        price.setTotalPrice(String.valueOf(itemAssemly.getTotalPrice()));
                        insertAssemly.add(price);
                    }
                    dfQuotationPriceService.saveBatch(insertAssemly);
                }


                type = NormalOutQuotationaSubEnum.DESIGN_FEE.getCn();
                List<DfQuotationPrice> insertDesign = Lists.newArrayList();
                if (null != detailData.getDesignCost()) {
                    for (ItemDesign itemDesign : detailData.getDesignCost().getDataList()) {
                        price = new DfQuotationPrice();
                        price.setMoldSelectionId(moldSelectionId);
                        price.setDetailId(detail.getId());
                        price.setType(type);
                        price.setName(itemDesign.getItemName());
                        price.setNum(String.valueOf(itemDesign.getHour()));
                        price.setPrice(String.valueOf(itemDesign.getPrice()));
                        price.setTotalPrice(String.valueOf(itemDesign.getTotalPrice()));
                        insertDesign.add(price);
                    }
                    dfQuotationPriceService.saveBatch(insertDesign);
                }


                type = NormalOutQuotationaSubEnum.MANUFACTURING_COST.getCn();
                List<DfQuotationPrice> insertManufacturing = Lists.newArrayList();
                if (null != detailData.getManufacturingCost()) {
                    for (ItemManufacturing itemManufactur : detailData.getManufacturingCost().getDataList()) {
                        price = new DfQuotationPrice();
                        price.setMoldSelectionId(moldSelectionId);
                        price.setDetailId(detail.getId());
                        price.setType(type);
                        price.setName(itemManufactur.getItemName());
                        price.setNum(String.valueOf(itemManufactur.getHour()));
                        price.setPrice(String.valueOf(itemManufactur.getPrice()));
                        price.setTotalPrice(String.valueOf(itemManufactur.getTotalPrice()));
                        insertManufacturing.add(price);
                    }
                    dfQuotationPriceService.saveBatch(insertManufacturing);
                }


                type = NormalOutQuotationaSubEnum.CMM_MEASURE.getCn();
                List<DfQuotationPrice> insertCmm = Lists.newArrayList();
                if (null != detailData.getCMMMeasure()) {
                    for (ItemCMMM itemCMMM : detailData.getCMMMeasure().getDataList()) {
                        price = new DfQuotationPrice();
                        price.setMoldSelectionId(moldSelectionId);
                        price.setDetailId(detail.getId());
                        price.setType(type);
                        price.setNum(String.valueOf(itemCMMM.getHour()));
                        price.setPrice(String.valueOf(itemCMMM.getPrice()));
                        price.setTotalPrice(String.valueOf(itemCMMM.getTotalPrice()));
                        price.setName(itemCMMM.getItemName());
                        insertCmm.add(price);
                    }
                    dfQuotationPriceService.saveBatch(insertCmm);
                }

                type = NormalOutQuotationaSubEnum.OTHER_FEE.getCn();
                List<DfQuotationPrice> insertOther = Lists.newArrayList();
                if (null != detailData.getOtherFee()) {
                    for (ItemOther itemOther : detailData.getOtherFee().getDataList()) {
                        price = new DfQuotationPrice();
                        price.setMoldSelectionId(moldSelectionId);
                        price.setDetailId(detail.getId());
                        price.setType(type);
                        price.setName(itemOther.getFeeName());
                        price.setNum(itemOther.getFeeDesc());
                        price.setTotalPrice(String.valueOf(itemOther.getTotalPrice()));
                        insertOther.add(price);
                    }
                    dfQuotationPriceService.saveBatch(insertOther);
                }

            }
            transactionManager.commit(status);
        } catch (RuntimeException e) {
            transactionManager.rollback(status);
            log.error("保存东风报价单时失败:{}", e.toString(), e);
            return JSON.toJSONString(R.fail(e.getMessage()));
        } catch (Exception e) {
            transactionManager.rollback(status);
            log.error("保存东风报价单时失败:{}", e.toString(), e);
            return JSON.toJSONString(R.fail("保存失败"));
        }
        return JSONObject.toJSONString(R.success("保存成功"));

    }

    @Override
    public String saveJLOutQuotation(JSONObject jsonObject) {
        //开启事务
        TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        try {
            jlQuotationService.remove(new LambdaQueryWrapper<JlQuotation>().eq(JlQuotation::getMoldSelectionId, moldSelectionId));
            jlQuotationDetailService.remove(new LambdaQueryWrapper<JlQuotationDetail>().eq(JlQuotationDetail::getMoldSelectionId, moldSelectionId));
            jlQuotationPriceService.remove(new LambdaQueryWrapper<JlQuotationPrice>().eq(JlQuotationPrice::getMoldSelectionId, moldSelectionId));

            JlQuotation jlQuotation = JSONObject.parseObject(jsonObject.toJSONString(), JlQuotation.class);
            jlQuotation.setTel(jsonObject.getString("telphone"));
            jlQuotation.setContact(jsonObject.getString("contactName"));
            jlQuotation.setPhone(jsonObject.getString("contactPhone"));
            jlQuotation.setId(IdUtils.simpleUUID());
            jlQuotationService.save(jlQuotation);
            //吉利外部明细
            JSONArray jlQuotationDataList = jsonObject.getJSONArray("dataList");
            for (int i = 0; i < jlQuotationDataList.size(); i++) {
                List<JlQuotationPrice> jlQuotationPriceList = new ArrayList<>();
                JSONObject jsonObject1 = jlQuotationDataList.getJSONObject(i);
                //吉利
                JlQuotationDetail jlQuotationDetail = JSONObject.parseObject(String.valueOf(jsonObject1), JlQuotationDetail.class);
                jlQuotationDetail.setProductName(jsonObject1.getString("nameOfProduct"));
                jlQuotationDetail.setProductCode(jsonObject1.getString("codeOfProduct"));
                jlQuotationDetail.setPress(jsonObject1.getString("pressTon"));
                jlQuotationDetail.setProfit(BigdecimalUtil.stringTo2DecimalString(jsonObject1.getString("profitFee")));
                jlQuotationDetail.setMoldTotalFee(BigdecimalUtil.stringTo2DecimalString(jsonObject1.getString("mouldFee")));
                jlQuotationDetail.setRemark(jsonObject1.getString("remark"));
                //选模表ID
                jlQuotationDetail.setMoldSelectionId(jlQuotation.getMoldSelectionId());
                jlQuotationDetail.setId(IdUtils.simpleUUID());
                //分表
                JSONObject detailData = jsonObject1.getJSONObject("detailData");
                JSONObject profitObj = detailData.getJSONObject("profitObj");
                String ratio = profitObj.getString("ratio");
                jlQuotationDetail.setProfit(BigdecimalUtil.stringTo2DecimalString(profitObj.getString("subTotal")));
                jlQuotationDetail.setProfitRatio(ratio);
                //原材料
                JSONObject rawMaterial = detailData.getJSONObject(JlQuotationEnum.RAW_MATERIAL.getCode());
                jlQuotationDetail.setMaterialFee(BigdecimalUtil.stringTo2DecimalString(rawMaterial.getString("subTotal")));

                this.dealWithPriceData(rawMaterial, jlQuotation.getMoldSelectionId(), jlQuotationDetail.getId(), jlQuotationPriceList, JlQuotationEnum.RAW_MATERIAL);

                //标准件
                JSONObject standardComponent = detailData.getJSONObject(JlQuotationEnum.STANDARD_COMPONENT.getCode());
                //标准件小计
                jlQuotationDetail.setStandardComponentFee(BigdecimalUtil.stringTo2DecimalString(standardComponent.getString("subTotal")));
                this.dealWithPriceData(standardComponent, jlQuotation.getMoldSelectionId(), jlQuotationDetail.getId(), jlQuotationPriceList, JlQuotationEnum.STANDARD_COMPONENT);

                //人工费
                JSONObject artificialFee = detailData.getJSONObject(JlQuotationEnum.ARTIFICIAL_FEE.getCode());
                //人工费小计
                jlQuotationDetail.setArtificialFee(BigdecimalUtil.stringTo2DecimalString(artificialFee.getString("subTotal")));
                this.dealWithPriceData(artificialFee, jlQuotation.getMoldSelectionId(), jlQuotationDetail.getId(), jlQuotationPriceList, JlQuotationEnum.ARTIFICIAL_FEE);

                //制造费
                JSONObject manufacturingFee = detailData.getJSONObject(JlQuotationEnum.MANUFACTURING_FEE.getCode());
                jlQuotationDetail.setManufacturingFee(BigdecimalUtil.stringTo2DecimalString(manufacturingFee.getString("subTotal")));
                this.dealWithPriceData(manufacturingFee, jlQuotation.getMoldSelectionId(), jlQuotationDetail.getId(), jlQuotationPriceList, JlQuotationEnum.MANUFACTURING_FEE);

                //装配费
                JSONObject assemblyFee = detailData.getJSONObject(JlQuotationEnum.ASSEMBLY_FEE.getCode());
                jlQuotationDetail.setAssemblyFee(BigdecimalUtil.stringTo2DecimalString(assemblyFee.getString("subTotal")));
                this.dealWithPriceData(assemblyFee, jlQuotation.getMoldSelectionId(), jlQuotationDetail.getId(), jlQuotationPriceList, JlQuotationEnum.ASSEMBLY_FEE);

                //调试费
                JSONObject debugFee = detailData.getJSONObject(JlQuotationEnum.DEBUG_FEE.getCode());
                jlQuotationDetail.setDebugFee(BigdecimalUtil.stringTo2DecimalString(debugFee.getString("subTotal")));
                this.dealWithPriceData(debugFee, jlQuotation.getMoldSelectionId(), jlQuotationDetail.getId(), jlQuotationPriceList, JlQuotationEnum.DEBUG_FEE);

                //测量费
                JSONObject measureFee = detailData.getJSONObject(JlQuotationEnum.MEASURE_FEE.getCode());
                jlQuotationDetail.setMeasureFee(BigdecimalUtil.stringTo2DecimalString(measureFee.getString("subTotal")));
                this.dealWithPriceData(measureFee, jlQuotation.getMoldSelectionId(), jlQuotationDetail.getId(), jlQuotationPriceList, JlQuotationEnum.MEASURE_FEE);

                //运输费
                JSONObject transportFee = detailData.getJSONObject(JlQuotationEnum.TRANSPORT_FEE.getCode());
                jlQuotationDetail.setTransportFee(BigdecimalUtil.stringTo2DecimalString(transportFee.getString("subTotal")));
                this.dealWithPriceData(transportFee, jlQuotation.getMoldSelectionId(), jlQuotationDetail.getId(), jlQuotationPriceList, JlQuotationEnum.TRANSPORT_FEE);

                //保存详情主表
                jlQuotationDetailService.save(jlQuotationDetail);

                jlQuotationPriceService.saveBatch(jlQuotationPriceList);
            }
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            return JSON.toJSONString(R.fail(e.getMessage()));
        }

        //jsonobject解析获取备用参数1
        String param1 = jsonObject.getString("param1");
        //jsonobject解析获取备用参数2
        String param2 = jsonObject.getString("param2");

        return JSON.toJSONString(R.success("保存成功"));
    }

    /**
     * 处理分表数据
     *
     * @param jsonObject
     * @param moldSelectionId
     * @param detailId
     * @param jlQuotationPriceList
     * @param jlQuotationEnum
     */
    private void dealWithPriceData(JSONObject jsonObject, String moldSelectionId, String detailId,
                                   List<JlQuotationPrice> jlQuotationPriceList, JlQuotationEnum jlQuotationEnum) {
        //调试费
        if (jlQuotationEnum.getCode().equals(JlQuotationEnum.DEBUG_FEE.getCode())) {
            JlPriceVo debugObj = jsonObject.getObject("debugObj", JlPriceVo.class);
            JlPriceVo tryoutObj = jsonObject.getObject("tryoutObj", JlPriceVo.class);

            JlQuotationPrice debugObjJlQuotationPrice = new JlQuotationPrice();
            debugObjJlQuotationPrice.setId(IdUtils.simpleUUID());
            debugObjJlQuotationPrice.setMoldSelectionId(moldSelectionId);
            debugObjJlQuotationPrice.setDetailId(detailId);
            debugObjJlQuotationPrice.setType(jlQuotationEnum.getName());
            debugObjJlQuotationPrice.setName("试模");
            if (null != debugObj) {
                debugObjJlQuotationPrice.setNum(BigdecimalUtil.stringToIntegerString(debugObj.getHour()));
                debugObjJlQuotationPrice.setPrice(BigdecimalUtil.stringTo2DecimalString(debugObj.getPrice()));
                debugObjJlQuotationPrice.setTotalPrice(BigdecimalUtil.stringTo2DecimalString(debugObj.getTotalPrice()));
            } else {
                debugObjJlQuotationPrice.setNum("0");
                debugObjJlQuotationPrice.setPrice("0.00");
                debugObjJlQuotationPrice.setTotalPrice("0.00");
            }

            jlQuotationPriceList.add(debugObjJlQuotationPrice);

            JlQuotationPrice tryoutObjJlQuotationPrice = new JlQuotationPrice();
            tryoutObjJlQuotationPrice.setId(IdUtils.simpleUUID());
            tryoutObjJlQuotationPrice.setMoldSelectionId(moldSelectionId);
            tryoutObjJlQuotationPrice.setDetailId(detailId);
            tryoutObjJlQuotationPrice.setType(jlQuotationEnum.getName());
            tryoutObjJlQuotationPrice.setName("回厂调试");
            if (null != tryoutObj) {
                tryoutObjJlQuotationPrice.setNum(BigdecimalUtil.stringTo1DecimalString(tryoutObj.getCount()));
                tryoutObjJlQuotationPrice.setPrice(BigdecimalUtil.stringTo2DecimalString(tryoutObj.getPrice()));
                tryoutObjJlQuotationPrice.setTotalPrice(BigdecimalUtil.stringTo2DecimalString(tryoutObj.getTotalPrice()));
            } else {
                tryoutObjJlQuotationPrice.setNum("0.0");
                tryoutObjJlQuotationPrice.setPrice("0.00");
                tryoutObjJlQuotationPrice.setTotalPrice("0.00");
            }

            jlQuotationPriceList.add(tryoutObjJlQuotationPrice);
        } else {
            JSONArray dataList = jsonObject.getJSONArray("dataList");
            if (ObjectUtil.isEmpty(dataList)) {
                return;
            }
            List<JlPriceVo> jlPriceVoList = JSONArray.parseArray(String.valueOf(dataList), JlPriceVo.class);
            jlPriceVoList.forEach(jlPriceVo -> {
                JlQuotationPrice jlQuotationPrice = new JlQuotationPrice();
                jlQuotationPrice.setId(IdUtils.simpleUUID());
                jlQuotationPrice.setMoldSelectionId(moldSelectionId);
                jlQuotationPrice.setDetailId(detailId);
                jlQuotationPrice.setType(jlQuotationEnum.getName());
                jlQuotationPrice.setName(jlPriceVo.getItemName());
                jlQuotationPrice.setSpecification(jlPriceVo.getSpecification());
                jlQuotationPrice.setSupplier(jlPriceVo.getModelNumber());
                jlQuotationPrice.setLength(jlPriceVo.getLength());
                jlQuotationPrice.setWidth(jlPriceVo.getWidth());
                jlQuotationPrice.setHeight(jlPriceVo.getHeight());
                //原材料、运输费
                if (jlQuotationEnum.getCode().equals(JlQuotationEnum.RAW_MATERIAL.getCode())
                        || jlQuotationEnum.getCode().equals(JlQuotationEnum.TRANSPORT_FEE.getCode())) {
                    jlQuotationPrice.setNum(BigdecimalUtil.stringTo3DecimalString(jlPriceVo.getWeight()));
                }
                //标准件
                if (jlQuotationEnum.getCode().equals(JlQuotationEnum.STANDARD_COMPONENT.getCode())) {
                    jlQuotationPrice.setNum(BigdecimalUtil.stringToIntegerString(jlPriceVo.getCount()));
                }
                //人工费、制造费、装配费、测量费
                if (jlQuotationEnum.getCode().equals(JlQuotationEnum.ARTIFICIAL_FEE.getCode())
                        || jlQuotationEnum.getCode().equals(JlQuotationEnum.MANUFACTURING_FEE.getCode())
                        || jlQuotationEnum.getCode().equals(JlQuotationEnum.ASSEMBLY_FEE.getCode())
                        || jlQuotationEnum.getCode().equals(JlQuotationEnum.MEASURE_FEE.getCode())) {
                    jlQuotationPrice.setNum(BigdecimalUtil.stringTo1DecimalString(jlPriceVo.getHour()));
                }
                jlQuotationPrice.setPrice(BigdecimalUtil.stringTo2DecimalString(jlPriceVo.getPrice()));
                jlQuotationPrice.setTotalPrice(BigdecimalUtil.stringTo2DecimalString(jlPriceVo.getTotalPrice()));
                jlQuotationPriceList.add(jlQuotationPrice);
            });
        }

    }

    @Override
    public String getQROutQuotation(JSONObject jsonObject) {
        if (jsonObject == null || jsonObject.size() < 1) {
            return JSON.toJSONString(R.fail("参数错误"));
        }
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        QrQuotationVo qrQuotationRespVo = new QrQuotationVo();
        //查询奇瑞报价单信息
        LambdaQueryWrapper<QrQuotation> qrQuotationQueryWrapper = new QueryWrapper<QrQuotation>()
                .lambda()
                .eq(QrQuotation::getMoldSelectionId, moldSelectionId);
        QrQuotation qrQuotation = iQrQuotationService.getOne(qrQuotationQueryWrapper);
        //初始化
        if (Objects.isNull(qrQuotation)) {
            LambdaQueryWrapper<TestModelParam> testModelParamLambdaQueryWrapper = new QueryWrapper<TestModelParam>()
                    .lambda()
                    .eq(TestModelParam::getMoldSelectionId, moldSelectionId)
                    .orderByAsc(TestModelParam::getMoldId);
            List<TestModelParam> modelParamList = testModelParamService.list(testModelParamLambdaQueryWrapper);
            if (!CollectionUtils.isEmpty(modelParamList)) {
                qrQuotation = new QrQuotation();
                qrQuotation.setId(IdUtils.simpleUUID());
                qrQuotation.setMoldSelectionId(moldSelectionId);
                iQrQuotationService.save(qrQuotation);
                for (TestModelParam testModelParam : modelParamList) {
                    QrQuotationDetail detail = new QrQuotationDetail();
                    detail.setId(IdUtils.simpleUUID());
                    detail.setProductName(testModelParam.getProductName());
                    detail.setProductCode(testModelParam.getProductCode());
                    detail.setProductSize(testModelParam.getProductSize());
                    detail.setProductLength(testModelParam.getProductLength());
                    detail.setProductWidth(testModelParam.getProductWidth());
                    detail.setProductHeight(testModelParam.getProductHeight());
                    detail.setCavityNum(testModelParam.getCavityNum());

                    detail.setMoldName(testModelParam.getMoldName());
                    detail.setMoldSize(testModelParam.getMoldSize());
                    detail.setMoldLength(testModelParam.getMoldLength());
                    detail.setMoldWidth(testModelParam.getMoldWidth());
                    detail.setMoldHeight(testModelParam.getMoldHeight());
                    detail.setLongevity(testModelParam.getLongevity());
                    detail.setMoldSelectionId(moldSelectionId);
                    iQrQuotationDetailService.save(detail);

                    //初始化外部分表数据
                    List<QrQuotationPrice> priceList = Arrays.stream(NormalQrQuotationaPriceEnum.values()).map(normalOutQuotationaPriceEnum -> {
                        QrQuotationPrice price = new QrQuotationPrice();
                        price.setId(IdUtils.simpleUUID());
                        price.setDetailId(detail.getId());
                        price.setMoldSelectionId(moldSelectionId);
                        price.setType(normalOutQuotationaPriceEnum.getType());
                        price.setName(normalOutQuotationaPriceEnum.getItemName());
                        price.setPrice(null);
                        price.setLength(null);
                        price.setWidth(null);
                        price.setHeight(null);
                        price.setNum(null);
                        price.setTotalPrice(null);
                        return price;
                    }).collect(Collectors.toList());
                    iQrQuotationPriceService.saveBatch(priceList);
                }
            }
        }
        if (Objects.nonNull(qrQuotation)) {
            qrQuotationRespVo.setCMMMeasureFeeTotal(Double.valueOf(qrQuotation.getCmmMeasure()));
            qrQuotationRespVo.setAssemlyMaterialFeeTotal(Double.valueOf(qrQuotation.getAssemlyMaterialCost()));
            qrQuotationRespVo.setDesignFeeTotal(Double.valueOf(qrQuotation.getDesignCost()));
            qrQuotationRespVo.setHeatTreatmentFeeTotal(Double.valueOf(qrQuotation.getHeatTreatment()));
            qrQuotationRespVo.setManagementFeeTotal(Double.valueOf(qrQuotation.getManagementFee()));
            qrQuotationRespVo.setManufacturingFeeTotal(Double.valueOf(qrQuotation.getManufacturingCost()));
            qrQuotationRespVo.setMoldSelectionId(moldSelectionId);
            qrQuotationRespVo.setProfitTotal(Double.valueOf(qrQuotation.getProfit()));
            qrQuotationRespVo.setTaxIncludedFeeTotal(Double.valueOf(qrQuotation.getPriceWithTax()));
            qrQuotationRespVo.setTransportFeeTotal(Double.valueOf(qrQuotation.getTransportFee()));
            qrQuotationRespVo.setTryoutFeeTotal(Double.valueOf(qrQuotation.getTryoutFee()));
            qrQuotationRespVo.setUnit(qrQuotation.getUnit());
            qrQuotationRespVo.setWorkMaterialFeeTotal(Double.valueOf(qrQuotation.getMachiningMaterialCost()));
            qrQuotationRespVo.setRemark(qrQuotation.getRemark());
            qrQuotationRespVo.setSignature(qrQuotation.getSignature());
            qrQuotationRespVo.setDate(qrQuotation.getDate());
            //处理奇瑞报价详情逻辑
            LambdaQueryWrapper<QrQuotationDetail> quotationDetailLambdaQueryWrapper = new QueryWrapper<QrQuotationDetail>()
                    .lambda()
                    .eq(QrQuotationDetail::getMoldSelectionId, moldSelectionId)
                    .orderByAsc(QrQuotationDetail::getId);
            List<QrQuotationDetail> qrQuotationDetailList = iQrQuotationDetailService.list(quotationDetailLambdaQueryWrapper);

            QrQuotation finalQrQuotation = qrQuotation;
            List<QrQuotationDetailVo> qrQuotationDetailResVoList = qrQuotationDetailList.stream().map(qrQuotationDetail -> {
                QrQuotationDetailVo qrQuotationDetailRespVo = new QrQuotationDetailVo();
                qrQuotationDetailRespVo.setCMMMeasureFeeListTotal(Double.valueOf(qrQuotationDetail.getCmmMeasure()));
                qrQuotationDetailRespVo.setAssemlyMaterialFeeListTotal(Double.valueOf(qrQuotationDetail.getAssemlyMaterialCost()));
                qrQuotationDetailRespVo.setCavityCount(qrQuotationDetail.getCavityNum());
                qrQuotationDetailRespVo.setCodeOfProduct(qrQuotationDetail.getProductCode());
                qrQuotationDetailRespVo.setDesignFeeListTotal(Double.valueOf(qrQuotationDetail.getDesignCost()));
                qrQuotationDetailRespVo.setHeatTreatmentFeeListTotal(Double.valueOf(qrQuotationDetail.getHeatTreatment()));
                qrQuotationDetailRespVo.setManufacturingFeeListTotal(Double.valueOf(qrQuotationDetail.getManufacturingCost()));
                qrQuotationDetailRespVo.setManagementFeeListTotal(Double.valueOf(qrQuotationDetail.getManagementFee()));
                qrQuotationDetailRespVo.setModuleCount(qrQuotationDetail.getMoldNum());
                qrQuotationDetailRespVo.setNameOfcodeOfProduct(qrQuotationDetail.getProductName());
                qrQuotationDetailRespVo.setProfitListTotal(Double.valueOf(qrQuotationDetail.getProfit()));
                qrQuotationDetailRespVo.setRemark(qrQuotationDetail.getRemark());
                qrQuotationDetailRespVo.setTaxIncludedFeeListTotal(Double.valueOf(qrQuotationDetail.getPriceWithTax()));
                qrQuotationDetailRespVo.setTransportFeeListTotal(Double.valueOf(qrQuotationDetail.getTransportFee()));
                qrQuotationDetailRespVo.setTryoutFeeListTotal(Double.valueOf(qrQuotationDetail.getTryoutFee()));
                qrQuotationDetailRespVo.setTypeName(qrQuotationDetail.getProductType());
                qrQuotationDetailRespVo.setWorkMaterialFeeListTotal(Double.valueOf(qrQuotationDetail.getMachiningMaterialCost()));
                qrQuotationDetailRespVo.setParam1(qrQuotationDetail.getParam1());
                qrQuotationDetailRespVo.setSubTableId(qrQuotationDetail.getId());

                QrQuotationSubDetailVo qrQuotationaSubDetailResVo = new QrQuotationSubDetailVo();
                qrQuotationaSubDetailResVo.setT0Time(qrQuotationDetail.gett1Time());
                qrQuotationaSubDetailResVo.setCavityCount(qrQuotationDetail.getCavityNum());
                qrQuotationaSubDetailResVo.setCodeOfcodeOfProduct(qrQuotationDetail.getProductCode());
                qrQuotationaSubDetailResVo.setContacts(qrQuotationDetail.getContacts());
                qrQuotationaSubDetailResVo.setDate(qrQuotationDetail.getDate());
                qrQuotationaSubDetailResVo.setDrawingNo(qrQuotationDetail.getDrawing());
                qrQuotationaSubDetailResVo.setHeightOfShape(Double.valueOf(qrQuotationDetail.getMoldHeight()));
                qrQuotationaSubDetailResVo.setHeightOfcodeOfProduct(Double.valueOf(qrQuotationDetail.getProductHeight()));
                qrQuotationaSubDetailResVo.setLeadTime(qrQuotationDetail.getLeadTime());
                qrQuotationaSubDetailResVo.setLengthOfShape(Double.valueOf(qrQuotationDetail.getMoldLength()));
                qrQuotationaSubDetailResVo.setLengthOfcodeOfProduct(Double.valueOf(qrQuotationDetail.getProductLength()));
                qrQuotationaSubDetailResVo.setLongevity(qrQuotationDetail.getLongevity());
                qrQuotationaSubDetailResVo.setMoldName(qrQuotationDetail.getMoldName());
                qrQuotationaSubDetailResVo.setMoldWeight(Double.valueOf(qrQuotationDetail.getMoldWeight()));
                qrQuotationaSubDetailResVo.setMouldFee(Double.valueOf(qrQuotationDetail.getMoldTotalFee()));
                qrQuotationaSubDetailResVo.setPressTon(qrQuotationDetail.getPress());
                qrQuotationaSubDetailResVo.setSignature(qrQuotationDetail.getSignature());
                qrQuotationaSubDetailResVo.setSupplier(qrQuotationDetail.getSupplier());
                qrQuotationaSubDetailResVo.setTelphone(qrQuotationDetail.getPhone());
                qrQuotationaSubDetailResVo.setWeightOfcodeOfProduct(Double.valueOf(qrQuotationDetail.getProductWeight()));
                qrQuotationaSubDetailResVo.setWidthOfShape(Double.valueOf(qrQuotationDetail.getMoldWidth()));
                qrQuotationaSubDetailResVo.setWidthOfcodeOfProduct(Double.valueOf(qrQuotationDetail.getProductWidth()));

                //查询分表数据
                LambdaQueryWrapper<QrQuotationPrice> qrQuotationPriceLambdaQueryWrapper = new QueryWrapper<QrQuotationPrice>()
                        .lambda()
                        .eq(QrQuotationPrice::getDetailId, qrQuotationDetail.getId())
                        .orderByAsc(QrQuotationPrice::getId);
                List<QrQuotationPrice> qrQuotationPriceList = iQrQuotationPriceService.list(qrQuotationPriceLambdaQueryWrapper);
                Map<String, List<QrQuotationPrice>> subMap = qrQuotationPriceList.stream().collect(Collectors.groupingBy(QrQuotationPrice::getType, LinkedHashMap::new, Collectors.toList()));
                subMap.forEach((itemName, list) -> {
                    if (itemName.equals(NormalQrQuotationaSubEnum.MACHINING_MATERIAL_COST.getCn())) {
                        MachiningMaterialFee machiningMaterialFee = new MachiningMaterialFee();
                        List<MachiningMaterialFee.DataList> collect = list.stream().map(qrQuotationPrice ->
                                new MachiningMaterialFee().new DataList(qrQuotationPrice.getName(), qrQuotationPrice.getSpecification(),
                                        Double.valueOf(StringUtils.isBlank(qrQuotationPrice.getSupplier()) ? "0" : qrQuotationPrice.getSupplier()),
                                        Double.valueOf(qrQuotationPrice.getPrice()),
                                        Double.valueOf(qrQuotationPrice.getLength()),
                                        Double.valueOf(qrQuotationPrice.getWidth()),
                                        Double.valueOf(qrQuotationPrice.getHeight()),
                                        Double.valueOf(qrQuotationPrice.getNum()),
                                        Double.valueOf(qrQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        machiningMaterialFee.setDataList(collect);
                        machiningMaterialFee.setSubTotal(Double.valueOf(qrQuotationDetail.getMachiningMaterialCost()));

                        qrQuotationaSubDetailResVo.setMachiningMaterialFee(machiningMaterialFee);
                    } else if (itemName.equals(NormalQrQuotationaSubEnum.CMM_MEASURE.getCn())) {
                        QrCMMeasure cMMMeasure = new QrCMMeasure();
                        List<QrCMMeasure.DataList> collect = list.stream().map(qrQuotationPrice ->
                                new QrCMMeasure().new DataList(qrQuotationPrice.getName(),
                                        Double.valueOf(qrQuotationPrice.getPrice()),
                                        Double.valueOf(qrQuotationPrice.getNum()),
                                        Double.valueOf(qrQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        cMMMeasure.setDataList(collect);
                        cMMMeasure.setSubTotal(Double.valueOf(qrQuotationDetail.getCmmMeasure()));

                        qrQuotationaSubDetailResVo.setCMMMeasure(cMMMeasure);
                    } else if (itemName.equals(NormalQrQuotationaSubEnum.MANUFACTURING_COST.getCn())) {
                        ManufacturingFee manufacturingFee = new ManufacturingFee();
                        List<ManufacturingFee.DataList> collect = list.stream().map(qrQuotationPrice ->
                                new ManufacturingFee().new DataList(qrQuotationPrice.getName(),
                                        Double.valueOf(qrQuotationPrice.getPrice()),
                                        Double.valueOf(qrQuotationPrice.getNum()),
                                        Double.valueOf(qrQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        manufacturingFee.setDataList(collect);
                        manufacturingFee.setSubTotal(Double.valueOf(qrQuotationDetail.getManufacturingCost()));

                        qrQuotationaSubDetailResVo.setManufacturingFee(manufacturingFee);
                    } else if (itemName.equals(NormalQrQuotationaSubEnum.DESIGN_FEE.getCn())) {
                        com.xinchuang.domain.vo.qr.DesignFee designFee = new com.xinchuang.domain.vo.qr.DesignFee();
                        List<com.xinchuang.domain.vo.qr.DesignFee.DataList> collect = list.stream().map(qrQuotationPrice ->
                                new com.xinchuang.domain.vo.qr.DesignFee().new DataList(qrQuotationPrice.getName(),
                                        Double.valueOf(qrQuotationPrice.getPrice()),
                                        Double.valueOf(qrQuotationPrice.getNum()),
                                        Double.valueOf(qrQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        designFee.setDataList(collect);
                        designFee.setSubTotal(Double.valueOf(qrQuotationDetail.getDesignCost()));

                        qrQuotationaSubDetailResVo.setDesignFee(designFee);
                    } else if (itemName.equals(NormalQrQuotationaSubEnum.OTHER_FEE.getCn())) {
                        com.xinchuang.domain.vo.qr.OtherFee otherFee = new com.xinchuang.domain.vo.qr.OtherFee();
                        List<com.xinchuang.domain.vo.qr.OtherFee.DataList> collect = list.stream().map(qrQuotationPrice ->
                                new com.xinchuang.domain.vo.qr.OtherFee().new DataList(qrQuotationPrice.getName(),
                                        Double.valueOf(qrQuotationPrice.getPrice()),
                                        qrQuotationPrice.getNum(),
                                        Double.valueOf(qrQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        otherFee.setDataList(collect);
                        otherFee.setSubTotal(Double.valueOf(qrQuotationDetail.getOtherFee()));

                        qrQuotationaSubDetailResVo.setOtherFee(otherFee);
                    } else if (itemName.equals(NormalQrQuotationaSubEnum.ASSEMLY_MATERIAL_COST.getCn())) {
                        AssemlyMaterialFee assemlyMaterialFee = new AssemlyMaterialFee();
                        List<AssemlyMaterialFee.DataList> collect = list.stream().map(qrQuotationPrice ->
                                new AssemlyMaterialFee().new DataList(qrQuotationPrice.getName(),
                                        qrQuotationPrice.getSpecification(),
                                        qrQuotationPrice.getSupplier(),
                                        Double.valueOf(qrQuotationPrice.getPrice()),
                                        Integer.valueOf(qrQuotationPrice.getNum()),
                                        Double.valueOf(qrQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        assemlyMaterialFee.setDataList(collect);
                        assemlyMaterialFee.setSubTotal(Double.valueOf(qrQuotationDetail.getAssemlyMaterialCost()));

                        qrQuotationaSubDetailResVo.setAssemlyMaterialFee(assemlyMaterialFee);
                    } else if (itemName.equals(NormalQrQuotationaSubEnum.HEAT_TREATMENT.getCn())) {
                        HeatTreatmentFee heatTreatmentFee = new HeatTreatmentFee();
                        List<HeatTreatmentFee.DataList> collect = list.stream().map(qrQuotationPrice ->
                                new HeatTreatmentFee().new DataList(qrQuotationPrice.getName(),
                                        Double.valueOf(qrQuotationPrice.getPrice()),
                                        Double.valueOf(qrQuotationPrice.getNum()),
                                        Double.valueOf(qrQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        heatTreatmentFee.setDataList(collect);
                        heatTreatmentFee.setSubTotal(Double.valueOf(qrQuotationDetail.getHeatTreatment()));

                        qrQuotationaSubDetailResVo.setHeatTreatmentFee(heatTreatmentFee);
                    } else {
                        log.error("不支持的分表类型:{}", itemName);
                    }
                });

                qrQuotationDetailRespVo.setDetailData(qrQuotationaSubDetailResVo);

                return qrQuotationDetailRespVo;
            }).collect(Collectors.toList());

            qrQuotationRespVo.setDataList(qrQuotationDetailResVoList);
        }

        return JSON.toJSONString(R.data(qrQuotationRespVo), SerializerFeature.WriteNullStringAsEmpty);
    }

    @Transactional
    @Override
    public String saveQROutQuotation(JSONObject jsonObject) {
        try {
            QrQuotationVo qrQuotationReqVo = JSON.parseObject(jsonObject.toJSONString(), QrQuotationVo.class);

            //校验数据的合法性
            checkQuotationDataService.checkQrData(qrQuotationReqVo);

            String moldSelectionId = qrQuotationReqVo.getMoldSelectionId();
            //删除报价信息
            LambdaQueryWrapper<QrQuotation> qrQuotationLambdaQueryWrapper = new QueryWrapper<QrQuotation>()
                    .lambda()
                    .eq(QrQuotation::getMoldSelectionId, moldSelectionId);
            QrQuotation qrQuotation = iQrQuotationService.getOne(qrQuotationLambdaQueryWrapper);
            if (Objects.nonNull(qrQuotation)) {
                iQrQuotationService.remove(new LambdaQueryWrapper<QrQuotation>().eq(QrQuotation::getId, qrQuotation.getId()));
                iQrQuotationDetailService.remove(new QueryWrapper<QrQuotationDetail>().lambda().eq(QrQuotationDetail::getMoldSelectionId, qrQuotation.getMoldSelectionId()));
                iQrQuotationPriceService.remove(new QueryWrapper<QrQuotationPrice>().lambda().eq(QrQuotationPrice::getMoldSelectionId, moldSelectionId));
            }
            //保存奇瑞对外报价主表
            QrQuotation newQuotation = new QrQuotation();
            newQuotation.setId(IdUtils.simpleUUID());
            newQuotation.setMoldSelectionId(qrQuotationReqVo.getMoldSelectionId());
            newQuotation.setSignature(qrQuotationReqVo.getSignature());
            newQuotation.setDate(qrQuotationReqVo.getDate());
            newQuotation.setUnit(qrQuotationReqVo.getUnit());
            newQuotation.setMachiningMaterialCost(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getWorkMaterialFeeTotal()));
            newQuotation.setHeatTreatment(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getHeatTreatmentFeeTotal()));
            newQuotation.setAssemlyMaterialCost(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getAssemlyMaterialFeeTotal()));
            newQuotation.setDesignCost(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getDesignFeeTotal()));
            newQuotation.setManufacturingCost(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getManufacturingFeeTotal()));
            newQuotation.setCmmMeasure(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getCMMMeasureFeeTotal()));
            newQuotation.setManagementFee(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getManagementFeeTotal()));
            newQuotation.setProfit(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getProfitTotal()));
            newQuotation.setTryoutFee(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getTryoutFeeTotal()));
            newQuotation.setTransportFee(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getTransportFeeTotal()));
            newQuotation.setPriceWithTax(BigdecimalUtil.doubleTo2DecimalString(qrQuotationReqVo.getTaxIncludedFeeTotal()));
            newQuotation.setRemark(newQuotation.getRemark());
            iQrQuotationService.save(newQuotation);

            //保存奇瑞对外报价详情逻辑
            List<QrQuotationDetailVo> dataList = qrQuotationReqVo.getDataList();
            List<QrQuotationDetail> qrQuotationDetailList = new ArrayList<>();
            List<QrQuotationPrice> qrQuotationPriceList = new ArrayList<>();

            dataList.forEach(detailReqVo -> {
                QrQuotationDetail qrQuotationDetail = new QrQuotationDetail();
                qrQuotationDetail.setId(IdUtils.simpleUUID());
                qrQuotationDetail.setMoldSelectionId(moldSelectionId);
                qrQuotationDetail.setProductCode(detailReqVo.getCodeOfProduct());
                qrQuotationDetail.setProductName(detailReqVo.getNameOfcodeOfProduct());
                qrQuotationDetail.setProductType(detailReqVo.getTypeName());
                qrQuotationDetail.setCavityNum(detailReqVo.getCavityCount());
                qrQuotationDetail.setMoldNum(detailReqVo.getModuleCount());
                qrQuotationDetail.setManagementFee(BigdecimalUtil.doubleTo2DecimalString(detailReqVo.getManagementFeeListTotal()));
                qrQuotationDetail.setProfit(BigdecimalUtil.doubleTo2DecimalString(detailReqVo.getProfitListTotal()));
                qrQuotationDetail.setTryoutFee(BigdecimalUtil.doubleTo2DecimalString(detailReqVo.getTryoutFeeListTotal()));
                qrQuotationDetail.setTransportFee(BigdecimalUtil.doubleTo2DecimalString(detailReqVo.getTransportFeeListTotal()));
                qrQuotationDetail.setPriceWithTax(BigdecimalUtil.doubleTo2DecimalString(detailReqVo.getTaxIncludedFeeListTotal()));
                qrQuotationDetail.setRemark(detailReqVo.getRemark());


                QrQuotationSubDetailVo detailData = detailReqVo.getDetailData();
                if (Objects.nonNull(detailData)) {
                    qrQuotationDetail.setContacts(detailData.getContacts());
                    qrQuotationDetail.setPhone(detailData.getTelphone());
                    qrQuotationDetail.setMoldName(detailData.getMoldName());
                    qrQuotationDetail.sett1Time(detailData.getT0Time());
                    qrQuotationDetail.setProductSize(detailData.getLengthOfcodeOfProduct() + "*" + detailData.getWidthOfcodeOfProduct() + "*" + detailData.getHeightOfcodeOfProduct());
                    qrQuotationDetail.setProductLength(String.valueOf(detailData.getLengthOfcodeOfProduct()));
                    qrQuotationDetail.setProductWidth(String.valueOf(detailData.getWidthOfcodeOfProduct()));
                    qrQuotationDetail.setProductHeight(String.valueOf(detailData.getHeightOfcodeOfProduct()));
                    qrQuotationDetail.setProductWeight(String.valueOf(detailData.getWeightOfcodeOfProduct()));
                    qrQuotationDetail.setDrawing(detailData.getDrawingNo());
                    qrQuotationDetail.setLeadTime(detailData.getLeadTime());
                    qrQuotationDetail.setMoldSize(detailData.getLengthOfShape() + "*" + detailData.getWidthOfShape() + "*" + detailData.getHeightOfShape());
                    qrQuotationDetail.setMoldLength(String.valueOf(detailData.getLengthOfShape()));
                    qrQuotationDetail.setMoldWidth(String.valueOf(detailData.getWidthOfShape()));
                    qrQuotationDetail.setMoldHeight(String.valueOf(detailData.getHeightOfShape()));
                    qrQuotationDetail.setMoldWeight(String.valueOf(detailData.getMoldWeight()));
                    qrQuotationDetail.setLongevity(detailData.getLongevity());
                    qrQuotationDetail.setPress(detailData.getPressTon());
                    if (Objects.nonNull(detailData.getOtherFee())) {
                        qrQuotationDetail.setOtherFee(BigdecimalUtil.doubleTo2DecimalString(detailData.getOtherFee().getSubTotal()));
                    }
                    if (Objects.nonNull(detailData.getManufacturingFee())) {
                        qrQuotationDetail.setManufacturingCost(BigdecimalUtil.doubleTo2DecimalString(detailData.getManufacturingFee().getSubTotal()));
                    }
                    if (Objects.nonNull(detailData.getHeatTreatmentFee())) {
                        qrQuotationDetail.setHeatTreatment(BigdecimalUtil.doubleTo2DecimalString(detailData.getHeatTreatmentFee().getSubTotal()));
                    }
                    if (Objects.nonNull(detailData.getAssemlyMaterialFee())) {
                        qrQuotationDetail.setAssemlyMaterialCost(BigdecimalUtil.doubleTo2DecimalString(detailData.getAssemlyMaterialFee().getSubTotal()));
                    }
                    if (Objects.nonNull(detailData.getDesignFee())) {
                        qrQuotationDetail.setDesignCost(BigdecimalUtil.doubleTo2DecimalString(detailData.getDesignFee().getSubTotal()));
                    }
                    if (Objects.nonNull(detailData.getMachiningMaterialFee())) {
                        qrQuotationDetail.setMachiningMaterialCost(BigdecimalUtil.doubleTo2DecimalString(detailData.getMachiningMaterialFee().getSubTotal()));
                    }
                    if (Objects.nonNull(detailData.getCMMMeasure())) {
                        qrQuotationDetail.setCmmMeasure(BigdecimalUtil.doubleTo2DecimalString(detailData.getCMMMeasure().getSubTotal()));
                    }
                    qrQuotationDetail.setCmmMeasure(BigdecimalUtil.doubleTo2DecimalString(detailReqVo.getCMMMeasureFeeListTotal()));
                    qrQuotationDetail.setMoldTotalFee(BigdecimalUtil.doubleTo4DecimalString(detailData.getMouldFee()));
                    qrQuotationDetail.setSupplier(detailData.getSupplier());
                    qrQuotationDetail.setSignature(detailData.getSignature());
                    qrQuotationDetail.setStamp(detailData.getStamp());
                    qrQuotationDetail.setDate(detailData.getDate());
                    qrQuotationDetailList.add(qrQuotationDetail);


                    //保存奇瑞对外报价分表逻辑
                    MachiningMaterialFee machiningMaterialFee = detailData.getMachiningMaterialFee();
                    if (Objects.nonNull(machiningMaterialFee) && Objects.nonNull(machiningMaterialFee.getDataList())) {
                        List<MachiningMaterialFee.DataList> subDataList = machiningMaterialFee.getDataList();
                        List<QrQuotationPrice> list = subDataList.stream().map(sub -> {
                            QrQuotationPrice qrQuotationPrice = new QrQuotationPrice();
                            qrQuotationPrice.setId(IdUtils.simpleUUID());
                            qrQuotationPrice.setMoldSelectionId(moldSelectionId);
                            qrQuotationPrice.setDetailId(qrQuotationDetail.getId());
                            qrQuotationPrice.setType(NormalQrQuotationaSubEnum.MACHINING_MATERIAL_COST.getCn());
                            qrQuotationPrice.setHeight(BigdecimalUtil.double2IntegerString(sub.getHeight()));
                            qrQuotationPrice.setLength(BigdecimalUtil.double2IntegerString(sub.getLength()));
                            qrQuotationPrice.setWidth(BigdecimalUtil.double2IntegerString(sub.getWidth()));
                            qrQuotationPrice.setName(sub.getMaterial());
                            qrQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                            qrQuotationPrice.setSpecification(sub.getSpecification());
                            qrQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                            qrQuotationPrice.setNum(BigdecimalUtil.double2IntegerString(sub.getCount()));
                            qrQuotationPrice.setSupplier(BigdecimalUtil.doubleTo3DecimalString(sub.getWeight()));
                            return qrQuotationPrice;
                        }).collect(Collectors.toList());
                        qrQuotationPriceList.addAll(list);
                    }
                    HeatTreatmentFee heatTreatmentFee = detailData.getHeatTreatmentFee();
                    if (Objects.nonNull(heatTreatmentFee) && Objects.nonNull(heatTreatmentFee.getDataList())) {
                        List<HeatTreatmentFee.DataList> subDataList = heatTreatmentFee.getDataList();
                        List<QrQuotationPrice> list = subDataList.stream().map(sub -> {
                            QrQuotationPrice qrQuotationPrice = new QrQuotationPrice();
                            qrQuotationPrice.setId(IdUtils.simpleUUID());
                            qrQuotationPrice.setMoldSelectionId(moldSelectionId);
                            qrQuotationPrice.setDetailId(qrQuotationDetail.getId());
                            qrQuotationPrice.setType(NormalQrQuotationaSubEnum.HEAT_TREATMENT.getCn());
                            qrQuotationPrice.setName(sub.getItemName());
                            qrQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                            qrQuotationPrice.setNum(BigdecimalUtil.doubleTo3DecimalString(sub.getWeight()));
                            qrQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                            return qrQuotationPrice;
                        }).collect(Collectors.toList());
                        qrQuotationPriceList.addAll(list);
                    }
                    AssemlyMaterialFee assemlyMaterialFee = detailData.getAssemlyMaterialFee();
                    if (Objects.nonNull(assemlyMaterialFee) && Objects.nonNull(assemlyMaterialFee.getDataList())) {
                        List<AssemlyMaterialFee.DataList> subDataList = assemlyMaterialFee.getDataList();
                        List<QrQuotationPrice> list = subDataList.stream().map(sub -> {
                            QrQuotationPrice qrQuotationPrice = new QrQuotationPrice();
                            qrQuotationPrice.setId(IdUtils.simpleUUID());
                            qrQuotationPrice.setMoldSelectionId(moldSelectionId);
                            qrQuotationPrice.setDetailId(qrQuotationDetail.getId());
                            qrQuotationPrice.setType(NormalQrQuotationaSubEnum.ASSEMLY_MATERIAL_COST.getCn());
                            qrQuotationPrice.setName(sub.getItemName());
                            qrQuotationPrice.setSupplier(sub.getSupplie());
                            qrQuotationPrice.setSpecification(sub.getSpecification());
                            qrQuotationPrice.setNum(String.valueOf(sub.getCount()));
                            qrQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                            qrQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                            return qrQuotationPrice;
                        }).collect(Collectors.toList());
                        qrQuotationPriceList.addAll(list);
                    }
                    com.xinchuang.domain.vo.qr.DesignFee designFee = detailData.getDesignFee();
                    if (Objects.nonNull(designFee) && Objects.nonNull(designFee.getDataList())) {
                        List<com.xinchuang.domain.vo.qr.DesignFee.DataList> subDataList = designFee.getDataList();
                        List<QrQuotationPrice> list = subDataList.stream().map(sub -> {
                            QrQuotationPrice qrQuotationPrice = new QrQuotationPrice();
                            qrQuotationPrice.setId(IdUtils.simpleUUID());
                            qrQuotationPrice.setMoldSelectionId(moldSelectionId);
                            qrQuotationPrice.setDetailId(qrQuotationDetail.getId());
                            qrQuotationPrice.setType(NormalQrQuotationaSubEnum.DESIGN_FEE.getCn());
                            qrQuotationPrice.setName(sub.getItemName());
                            qrQuotationPrice.setNum(BigdecimalUtil.doubleTo1DecimalString(sub.getHour()));
                            qrQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                            qrQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                            return qrQuotationPrice;
                        }).collect(Collectors.toList());
                        qrQuotationPriceList.addAll(list);
                    }
                    ManufacturingFee manufacturingFee = detailData.getManufacturingFee();
                    if (Objects.nonNull(manufacturingFee) && Objects.nonNull(manufacturingFee.getDataList())) {
                        List<ManufacturingFee.DataList> subDataList = manufacturingFee.getDataList();
                        List<QrQuotationPrice> list = subDataList.stream().map(sub -> {
                            QrQuotationPrice qrQuotationPrice = new QrQuotationPrice();
                            qrQuotationPrice.setId(IdUtils.simpleUUID());
                            qrQuotationPrice.setMoldSelectionId(moldSelectionId);
                            qrQuotationPrice.setDetailId(qrQuotationDetail.getId());
                            qrQuotationPrice.setType(NormalQrQuotationaSubEnum.MANUFACTURING_COST.getCn());
                            qrQuotationPrice.setName(sub.getItemName());
                            qrQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                            qrQuotationPrice.setNum(BigdecimalUtil.doubleTo1DecimalString(sub.getHour()));
                            qrQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));

                            return qrQuotationPrice;
                        }).collect(Collectors.toList());
                        qrQuotationPriceList.addAll(list);
                    }
                    QrCMMeasure cmmMeasure = detailData.getCMMMeasure();
                    if (Objects.nonNull(cmmMeasure) && Objects.nonNull(cmmMeasure.getDataList())) {
                        List<QrCMMeasure.DataList> subDataList = cmmMeasure.getDataList();
                        List<QrQuotationPrice> list = subDataList.stream().map(sub -> {
                            QrQuotationPrice qrQuotationPrice = new QrQuotationPrice();
                            qrQuotationPrice.setId(IdUtils.simpleUUID());
                            qrQuotationPrice.setMoldSelectionId(moldSelectionId);
                            qrQuotationPrice.setDetailId(qrQuotationDetail.getId());
                            qrQuotationPrice.setType(NormalQrQuotationaSubEnum.CMM_MEASURE.getCn());
                            qrQuotationPrice.setName(sub.getItemName());
                            qrQuotationPrice.setNum(BigdecimalUtil.doubleTo1DecimalString(sub.getHour()));
                            qrQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                            qrQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                            return qrQuotationPrice;
                        }).collect(Collectors.toList());
                        qrQuotationPriceList.addAll(list);
                    }
                    com.xinchuang.domain.vo.qr.OtherFee otherFee = detailData.getOtherFee();
                    if (Objects.nonNull(otherFee) && Objects.nonNull(otherFee.getDataList())) {
                        List<com.xinchuang.domain.vo.qr.OtherFee.DataList> subDataList = otherFee.getDataList();
                        List<QrQuotationPrice> list = subDataList.stream().map(sub -> {
                            QrQuotationPrice qrQuotationPrice = new QrQuotationPrice();
                            qrQuotationPrice.setId(IdUtils.simpleUUID());
                            qrQuotationPrice.setMoldSelectionId(moldSelectionId);
                            qrQuotationPrice.setDetailId(qrQuotationDetail.getId());
                            qrQuotationPrice.setType(NormalQrQuotationaSubEnum.OTHER_FEE.getCn());
                            qrQuotationPrice.setName(sub.getItemName());
                            qrQuotationPrice.setNum(sub.getFeeDesc());
                            qrQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                            qrQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                            return qrQuotationPrice;
                        }).collect(Collectors.toList());
                        qrQuotationPriceList.addAll(list);
                    }
                } else {
                    qrQuotationDetailList.add(qrQuotationDetail);
                }
            });

            if (Objects.nonNull(qrQuotationDetailList) && !qrQuotationDetailList.isEmpty()) {
                iQrQuotationDetailService.saveBatch(qrQuotationDetailList);
            }
            if (Objects.nonNull(qrQuotationPriceList) && !qrQuotationPriceList.isEmpty()) {
                iQrQuotationPriceService.saveBatch(qrQuotationPriceList);
            }
        } catch (RuntimeException e) {
            log.error("保存奇瑞报价单时失败:{}", e.toString(), e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JSON.toJSONString(R.fail(e.getMessage()));
        } catch (Exception e) {
            log.error("保存奇瑞报价单时失败:{}", e.toString(), e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JSON.toJSONString(R.fail("保存失败"));
        }
        return JSON.toJSONString(R.success("保存成功"));

    }

    @Override
    public String getBYDOutQuotation(JSONObject jsonObject) {
        if (jsonObject == null || jsonObject.size() < 1) {
            return JSON.toJSONString(R.fail("参数错误"));
        }
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        //查询奇瑞报价单信息
        LambdaQueryWrapper<BydQuotation> bydQuotationQueryWrapper = new QueryWrapper<BydQuotation>()
                .lambda()
                .eq(BydQuotation::getMoldSelectionId, moldSelectionId);
        BydQuotation bydQuotation = iBydQuotationService.getOne(bydQuotationQueryWrapper);
        //初始化
        if (Objects.isNull(bydQuotation)) {
            LambdaQueryWrapper<TestModelParam> testModelParamLambdaQueryWrapper = new QueryWrapper<TestModelParam>()
                    .lambda()
                    .eq(TestModelParam::getMoldSelectionId, moldSelectionId)
                    .orderByAsc(TestModelParam::getMoldId);
            List<TestModelParam> modelParamList = testModelParamService.list(testModelParamLambdaQueryWrapper);
            if (!CollectionUtils.isEmpty(modelParamList)) {
                bydQuotation = new BydQuotation();
                bydQuotation.setId(IdUtils.simpleUUID());
                bydQuotation.setMoldSelectionId(moldSelectionId);
                iBydQuotationService.save(bydQuotation);
                for (TestModelParam testModelParam : modelParamList) {
                    BydQuotationDetail detail = new BydQuotationDetail();
                    detail.setId(IdUtils.simpleUUID());
                    detail.setQuotationId(bydQuotation.getId());
                    detail.setProductName(testModelParam.getProductName());
                    detail.setProductCode(testModelParam.getProductCode());
                    detail.setProductImage(testModelParam.getProductImage());
                    detail.setProductMaterial(testModelParam.getMaterials());
                    detail.setProductSize(testModelParam.getProductSize());
                    detail.setProductLength(testModelParam.getProductLength());
                    detail.setProductWidth(testModelParam.getProductWidth());
                    detail.setProductHeight(testModelParam.getProductHeight());
                    detail.setCavityNum(testModelParam.getCavityNum());
                    detail.setMoldSize(testModelParam.getMoldSize());
                    detail.setMoldLength(testModelParam.getMoldLength());
                    detail.setMoldWidth(testModelParam.getMoldWidth());
                    detail.setMoldHeight(testModelParam.getMoldHeight());
                    iBydQuotationDetailService.save(detail);

                    //初始化外部分表数据
                    List<BydQuotationPrice> priceList = Arrays.stream(NormalBYDQuotationaPriceEnum.values()).map(normalOutQuotationaPriceEnum -> {
                        BydQuotationPrice price = new BydQuotationPrice();
                        price.setId(IdUtils.simpleUUID());
                        price.setDetailId(detail.getId());
                        price.setMoldSelectionId(moldSelectionId);
                        price.setType(normalOutQuotationaPriceEnum.getType());
                        price.setName(normalOutQuotationaPriceEnum.getItemName());
                        price.setPrice(null);
                        price.setLength(null);
                        price.setWidth(null);
                        price.setHeight(null);
                        price.setNum(null);
                        price.setTotalPrice(null);
                        return price;
                    }).collect(Collectors.toList());
                    iBydQuotationPriceService.saveBatch(priceList);
                }

            }
        }
        BYDQuotationVo bydQuotationRespVo = new BYDQuotationVo();
        if (Objects.nonNull(bydQuotation)) {
            bydQuotationRespVo.setProjectName(bydQuotation.getProjectName());
            bydQuotationRespVo.setMoldSelectionId(bydQuotation.getMoldSelectionId());
            bydQuotationRespVo.setInspectionToolFeeTotal(Double.valueOf(bydQuotation.getCheckingFixtureFee()));
            bydQuotationRespVo.setModlueFeeTotal(Double.valueOf(bydQuotation.getPriceWithoutTax()));
            //处理BYD报价详情逻辑
            LambdaQueryWrapper<BydQuotationDetail> quotationDetailLambdaQueryWrapper = new QueryWrapper<BydQuotationDetail>()
                    .lambda()
                    .eq(BydQuotationDetail::getQuotationId, bydQuotation.getId())
                    .orderByAsc(BydQuotationDetail::getId);
            List<BydQuotationDetail> bydQuotationDetailList = iBydQuotationDetailService.list(quotationDetailLambdaQueryWrapper);
            BydQuotation finalBydQuotation = bydQuotation;
            List<BYDQuotationDetailVo> bydQuotationDetailResVoList = bydQuotationDetailList.stream().map(bydQuotationDetail -> {
                BYDQuotationDetailVo bydQuotationDetailRespVo = new BYDQuotationDetailVo();
                bydQuotationDetailRespVo.setRemark(bydQuotationDetail.getRemark());
                //样件单价
                bydQuotationDetailRespVo.setSamplePieceFee(Double.valueOf(bydQuotationDetail.getPrice()));
                //检具价格
                bydQuotationDetailRespVo.setInspectionToolFee(Double.valueOf(bydQuotationDetail.getCheckingFixtureFee()));
                //模具价格（未税）
                bydQuotationDetailRespVo.setModlueFee(Double.valueOf(bydQuotationDetail.getPriceWithoutTax()));
                //模穴数
                bydQuotationDetailRespVo.setCavityCount(bydQuotationDetail.getCavityNum());
                //周期
                bydQuotationDetailRespVo.setLifetime(bydQuotationDetail.getMakeTime());
                //表面状态
                bydQuotationDetailRespVo.setSurfaceStatus(bydQuotationDetail.getSurface());
                //材料
                bydQuotationDetailRespVo.setMaterial(bydQuotationDetail.getProductMaterial());
                //产品尺寸-高
                bydQuotationDetailRespVo.setHeightOfProduct(Double.valueOf(bydQuotationDetail.getProductHeight()));
                //产品尺寸-宽
                bydQuotationDetailRespVo.setWidthOfProduct(Double.valueOf(bydQuotationDetail.getProductWidth()));
                //产品名称
                bydQuotationDetailRespVo.setNameOfProduct(bydQuotationDetail.getProductName());
                //产品尺寸-长
                bydQuotationDetailRespVo.setLengthOfProduct(Double.valueOf(bydQuotationDetail.getProductLength()));
                //产品代号
                bydQuotationDetailRespVo.setCodeOfProduct(bydQuotationDetail.getProductCode());
                //类别
                bydQuotationDetailRespVo.setTypeName(bydQuotationDetail.getProductType());
                //图片
                bydQuotationDetailRespVo.setImageOfProduct(bydQuotationDetail.getProductImage());
                //分表Id
                bydQuotationDetailRespVo.setSubTableId(bydQuotationDetail.getId());

                BYDQuotationSubDetailVo bydQuotationaSubDetailResVo = new BYDQuotationSubDetailVo();
                //模穴数
                bydQuotationaSubDetailResVo.setCavityCount(bydQuotationDetail.getCavityNum());
                // 产品代号
                bydQuotationaSubDetailResVo.setCodeOfProduct(bydQuotationDetail.getProductCode());
                //项目名称
                bydQuotationaSubDetailResVo.setProjectName(null);
                //产品名称
                bydQuotationaSubDetailResVo.setNameOfProduct(bydQuotationDetail.getProductName());
                //表面要求
                bydQuotationaSubDetailResVo.setSurfaceRequire(bydQuotationDetail.getSurfaceRequire());
                //零件材料
                bydQuotationaSubDetailResVo.setMaterial(bydQuotationDetail.getProductMaterial());
                //报价金额
                bydQuotationaSubDetailResVo.setOfferFee(Double.valueOf(bydQuotationDetail.getPriceWithoutTax()));
                //模具量纲
                bydQuotationaSubDetailResVo.setMoldDimension(bydQuotationDetail.getMoldDimension());
                //模具总价(元) (RMB)
//                double priceWithoutTaxTotal = 0.0;
//                for (BydQuotationDetail quotationDetail : bydQuotationDetailList) {
//                    double priceWithoutTax = 0.0;
//                    if(null != quotationDetail.getPriceWithoutTax()){
//                        priceWithoutTax = Double.valueOf(quotationDetail.getPriceWithoutTax());
//                    }
//                    priceWithoutTaxTotal += priceWithoutTax;
//                }
//                bydQuotationaSubDetailResVo.setMouldFee(priceWithoutTaxTotal);
                bydQuotationaSubDetailResVo.setMouldFee(Double.valueOf(bydQuotationDetail.getPriceWithoutTax()));
                //模胚外形尺寸-长
                bydQuotationaSubDetailResVo.setLengthOfEmbryo(Double.valueOf(bydQuotationDetail.getMoldLength()));
                //模胚外形尺寸-宽
                bydQuotationaSubDetailResVo.setWidthOfEmbryo(Double.valueOf(bydQuotationDetail.getMoldWidth()));
                // 模胚外形尺寸-高
                bydQuotationaSubDetailResVo.setHeightOfEmbryo(Double.valueOf(bydQuotationDetail.getMoldHeight()));
                //模胚外形尺寸-重量
                bydQuotationaSubDetailResVo.setWeightOfEmbryo(Double.valueOf(bydQuotationDetail.getMoldWeight()));
                //产品尺寸-长
                bydQuotationaSubDetailResVo.setLengthOfProduct(Double.valueOf(bydQuotationDetail.getProductLength()));
                //产品尺寸-宽
                bydQuotationaSubDetailResVo.setWidthOfProduct(Double.valueOf(bydQuotationDetail.getProductWidth()));
                //产品尺寸-高
                bydQuotationaSubDetailResVo.setHeightOfProduct(Double.valueOf(bydQuotationDetail.getProductHeight()));
                //产品重量
                bydQuotationaSubDetailResVo.setWeightOfProduct(Double.valueOf(bydQuotationDetail.getProductWeight()));


                //查询分表数据
                LambdaQueryWrapper<BydQuotationPrice> qrQuotationPriceLambdaQueryWrapper = new QueryWrapper<BydQuotationPrice>()
                        .lambda()
                        .eq(BydQuotationPrice::getDetailId, bydQuotationDetail.getId())
                        .orderByAsc(BydQuotationPrice::getId);
                List<BydQuotationPrice> bydQuotationPriceList = iBydQuotationPriceService.list(qrQuotationPriceLambdaQueryWrapper);
                Map<String, List<BydQuotationPrice>> subMap = bydQuotationPriceList.stream()
                        .collect(Collectors.groupingBy(BydQuotationPrice::getType, LinkedHashMap::new, Collectors.toList()));
                subMap.forEach((itemName, list) -> {
                    if (itemName.equals(NormalBYDQuotationaSubEnum.MANUFACTURING.getCn())) {
                        //制造成本
                        ManufacturingFeeVo manufacturingFee = new ManufacturingFeeVo();
                        List<ManufacturingFeeVo.DataList> collect = list.stream().map(bydQuotationPrice ->
                                new ManufacturingFeeVo().new DataList(bydQuotationPrice.getName(),
                                        Double.valueOf(bydQuotationPrice.getNum()),
                                        Double.valueOf(bydQuotationPrice.getPrice()),
                                        Double.valueOf(StringUtils.isNotBlank(bydQuotationPrice.getSupplier()) ? bydQuotationPrice.getSupplier() : "0.00"),
                                        Double.valueOf(bydQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        manufacturingFee.setDataList(collect);
                        if (StringUtils.isNotBlank(bydQuotationDetail.getMachiningCost())) {
                            manufacturingFee.setSubTotal(Double.valueOf(bydQuotationDetail.getMachiningCost()));
                        }
                        bydQuotationaSubDetailResVo.setManufacturingFee(manufacturingFee);
                    } else if (itemName.equals(NormalBYDQuotationaSubEnum.STEEL.getCn())) {
                        //材料费用明细
                        SteelFeeVo steelFee = new SteelFeeVo();
                        List<SteelFeeVo.DataList> collect = list.stream().map(bydQuotationPrice ->
                                new SteelFeeVo().new DataList(
                                        bydQuotationPrice.getName(),
                                        bydQuotationPrice.getSpecification(),
                                        Double.valueOf(bydQuotationPrice.getLength()),
                                        Double.valueOf(bydQuotationPrice.getWidth()),
                                        Double.valueOf(bydQuotationPrice.getHeight()),
                                        MyUtils.convertToInt(bydQuotationPrice.getNum()),
                                        Double.valueOf(bydQuotationPrice.getNum()),
                                        Double.valueOf(StringUtils.isBlank(bydQuotationPrice.getSupplier()) ? "0" : bydQuotationPrice.getSupplier()),
                                        Double.valueOf(bydQuotationPrice.getPrice()),
                                        Double.valueOf(bydQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        steelFee.setDataList(collect);
                        if (StringUtils.isNotBlank(bydQuotationDetail.getMaterialCost())) {
                            steelFee.setSubTotal(Double.valueOf(bydQuotationDetail.getMaterialCost()));
                        }
                        bydQuotationaSubDetailResVo.setSteelFee(steelFee);
                    } else if (itemName.equals(NormalBYDQuotationaSubEnum.OPERATING.getCn())) {
                        //营业费用
                        OperatingFeeVo operatingFee = new OperatingFeeVo();
                        List<OperatingFeeVo.DataList> collect = list.stream().map(bydQuotationPrice ->
                                new OperatingFeeVo().new DataList(bydQuotationPrice.getName(),
                                        bydQuotationPrice.getNum(),
                                        Double.valueOf(bydQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        operatingFee.setDataList(collect);
                        if (StringUtils.isNotBlank(bydQuotationDetail.getOperatingMeasure())) {
                            operatingFee.setSubTotal(Double.valueOf(bydQuotationDetail.getOperatingMeasure()));
                        }
                        bydQuotationaSubDetailResVo.setOperatingFee(operatingFee);
                    } else if (itemName.equals(NormalBYDQuotationaSubEnum.OTHERACCESSORIES.getCn())) {
                        //其他辅件
                        OtherAccessoriesFeeVo otherAccessoriesFee = new OtherAccessoriesFeeVo();
                        List<OtherAccessoriesFeeVo.DataList> collect = list.stream().map(bydQuotationPrice ->
                                new OtherAccessoriesFeeVo().new DataList(bydQuotationPrice.getName(),
                                        bydQuotationPrice.getSpecification(),
                                        MyUtils.convertToInt(bydQuotationPrice.getNum()),
                                        Double.valueOf(bydQuotationPrice.getPrice()),
                                        Double.valueOf(bydQuotationPrice.getTotalPrice()),
                                        bydQuotationPrice.getSupplier())
                        ).collect(Collectors.toList());
                        otherAccessoriesFee.setDataList(collect);
                        if (StringUtils.isNotBlank(bydQuotationDetail.getOtherMaterialFee())) {
                            otherAccessoriesFee.setSubTotal(Double.valueOf(bydQuotationDetail.getOtherMaterialFee()));
                        }
                        bydQuotationaSubDetailResVo.setOtherAccessoriesFee(otherAccessoriesFee);
                    } else if (itemName.equals(NormalBYDQuotationaSubEnum.DESIGNCOST.getCn())) {
                        //设计费用
                        DesignCostVo designCost = new DesignCostVo();
                        List<DesignCostVo.DataList> collect = list.stream().map(bydQuotationPrice ->
                                new DesignCostVo().new DataList(bydQuotationPrice.getName(),
                                        Double.valueOf(bydQuotationPrice.getNum()),
                                        Double.valueOf(bydQuotationPrice.getPrice()),
                                        Double.valueOf(bydQuotationPrice.getTotalPrice()))
                        ).collect(Collectors.toList());
                        designCost.setDataList(collect);
                        if (StringUtils.isNotBlank(bydQuotationDetail.getDesignCost())) {
                            designCost.setSubTotal(Double.valueOf(bydQuotationDetail.getDesignCost()));
                        }
                        bydQuotationaSubDetailResVo.setDesignCost(designCost);
                    } else {
                        log.error("不支持的分表类型:{}", itemName);
                    }
                });
                bydQuotationDetailRespVo.setDetailData(bydQuotationaSubDetailResVo);
                return bydQuotationDetailRespVo;
            }).collect(Collectors.toList());
            bydQuotationRespVo.setDataList(bydQuotationDetailResVoList);
        }

        return JSON.toJSONString(R.data(bydQuotationRespVo), SerializerFeature.WriteNullStringAsEmpty);
    }

    @Transactional
    @Override
    public String saveBYDOutQuotation(JSONObject jsonObject) {

        try {
            //jsonobject解析获取选模表Id
            String moldSelectionId = jsonObject.getString("moldSelectionId");
            //封装数据
            BYDQuotationVo bydQuotationVo = JSONObject.parseObject(jsonObject.toJSONString(), BYDQuotationVo.class);

            //校验数据的合法性
            checkQuotationDataService.checkBYDData(bydQuotationVo);

            //删除报价信息
            LambdaQueryWrapper<BydQuotation> qrQuotationLambdaQueryWrapper = new QueryWrapper<BydQuotation>()
                    .lambda()
                    .eq(BydQuotation::getMoldSelectionId, moldSelectionId);
            BydQuotation bydQuo = iBydQuotationService.getOne(qrQuotationLambdaQueryWrapper);
            if (Objects.nonNull(bydQuo)) {
                iBydQuotationService.remove(new LambdaQueryWrapper<BydQuotation>().eq(BydQuotation::getId, bydQuo.getId()));
                iBydQuotationDetailService.remove(new QueryWrapper<BydQuotationDetail>().lambda().eq(BydQuotationDetail::getQuotationId, bydQuo.getId()));
                iQrQuotationPriceService.remove(new QueryWrapper<QrQuotationPrice>().lambda().eq(QrQuotationPrice::getMoldSelectionId, moldSelectionId));
            }
            //2、保存数据至主表
            BydQuotation bydQuotation = new BydQuotation();
            bydQuotation.setId(IdUtils.simpleUUID());
            bydQuotation.setMoldSelectionId(moldSelectionId);
            bydQuotation.setProjectName(bydQuotationVo.getProjectName());
            bydQuotation.setPriceWithoutTax(BigdecimalUtil.doubleTo2DecimalString(bydQuotationVo.getModlueFeeTotal()));
            bydQuotation.setCheckingFixtureFee(BigdecimalUtil.doubleTo2DecimalString(bydQuotationVo.getInspectionToolFeeTotal()));
            List<BYDQuotationDetailVo> dataList = bydQuotationVo.getDataList();
            double price = 0.0;
            for (BYDQuotationDetailVo quotationDetailVo : dataList) {
                double samplePieceFee = Double.valueOf(quotationDetailVo.getSamplePieceFee());
                price += samplePieceFee;
            }
            bydQuotation.setPrice(BigdecimalUtil.doubleTo2DecimalString(price));
            iBydQuotationService.saveOrUpdate(bydQuotation);

            //保存byd对外报价详情逻辑
            List<BydQuotationDetail> bydQuotationDetailList = new ArrayList<>();
            List<BydQuotationPrice> bydQuotationPriceList = new ArrayList<>();

            BydQuotationDetail detail = new BydQuotationDetail();

            dataList.forEach(detailReqVo -> {
                BydQuotationDetail bydQuotationDetail = new BydQuotationDetail();
                //主表id
                bydQuotationDetail.setId(IdUtils.simpleUUID());
                bydQuotationDetail.setQuotationId(bydQuotation.getId());
                bydQuotationDetail.setProductType(detailReqVo.getTypeName());
                bydQuotationDetail.setProductName(detailReqVo.getNameOfProduct());
                bydQuotationDetail.setProductCode(detailReqVo.getCodeOfProduct());
                bydQuotationDetail.setProductImage(detailReqVo.getImageOfProduct());
                bydQuotationDetail.setProductSize(detailReqVo.getLengthOfProduct() + "*" + detailReqVo.getWidthOfProduct() + "*" + detailReqVo.getHeightOfProduct());
                bydQuotationDetail.setProductLength(String.valueOf(detailReqVo.getLengthOfProduct()));
                bydQuotationDetail.setProductWidth(String.valueOf(detailReqVo.getWidthOfProduct()));
                bydQuotationDetail.setProductHeight(String.valueOf(detailReqVo.getHeightOfProduct()));
                bydQuotationDetail.setProductMaterial(detailReqVo.getMaterial());
                bydQuotationDetail.setSurface(detailReqVo.getSurfaceStatus());
                bydQuotationDetail.setSurfaceRequire(detailReqVo.getSurfaceStatus());
                bydQuotationDetail.setCavityNum(detailReqVo.getCavityCount());
                bydQuotationDetail.setMakeTime(detailReqVo.getLifetime());
                bydQuotationDetail.setPriceWithoutTax(BigdecimalUtil.doubleTo2DecimalString(detailReqVo.getModlueFee()));
                bydQuotationDetail.setCheckingFixtureFee(BigdecimalUtil.doubleTo2DecimalString(detailReqVo.getInspectionToolFee()));
                bydQuotationDetail.setPrice(BigdecimalUtil.doubleTo2DecimalString(detailReqVo.getSamplePieceFee()));
                bydQuotationDetail.setRemark(detailReqVo.getRemark());

                BYDQuotationSubDetailVo detailData = detailReqVo.getDetailData();
                bydQuotationDetail.setProductWeight(BigdecimalUtil.doubleTo3DecimalString(detailData.getWeightOfProduct()));

                bydQuotationDetail.setMoldDimension(detailData.getMoldDimension());
                bydQuotationDetail.setMoldSize(detailData.getLengthOfEmbryo() + "*" + detailData.getWidthOfEmbryo() + "*" + detailData.getHeightOfEmbryo());
                bydQuotationDetail.setMoldLength(String.valueOf(detailData.getLengthOfEmbryo()));
                bydQuotationDetail.setMoldWidth(String.valueOf(detailData.getWidthOfEmbryo()));
                bydQuotationDetail.setMoldHeight(String.valueOf(detailData.getHeightOfEmbryo()));
                bydQuotationDetail.setMoldWeight(String.valueOf(detailData.getWeightOfEmbryo()));
                if (null != detailData.getSteelFee()) {
                    bydQuotationDetail.setMaterialCost(BigdecimalUtil.doubleTo2DecimalString(detailData.getSteelFee().getSubTotal()));
                }
                if (null != detailData.getOtherAccessoriesFee()) {
                    bydQuotationDetail.setOtherMaterialFee(BigdecimalUtil.doubleTo2DecimalString(detailData.getOtherAccessoriesFee().getSubTotal()));
                }
                if (null != detailData.getManufacturingFee()) {
                    bydQuotationDetail.setMachiningCost(BigdecimalUtil.doubleTo2DecimalString(detailData.getManufacturingFee().getSubTotal()));
                }
                if (null != detailData.getOperatingFee()) {
                    bydQuotationDetail.setOperatingMeasure(BigdecimalUtil.doubleTo2DecimalString(detailData.getOperatingFee().getSubTotal()));
                }
                if (null != detailData.getDesignCost()) {
                    bydQuotationDetail.setDesignCost(BigdecimalUtil.doubleTo2DecimalString(detailData.getDesignCost().getSubTotal()));
                }
                bydQuotationDetailList.add(bydQuotationDetail);

                //保存BYD对外报价分表逻辑
                ManufacturingFeeVo manufacturingFee = detailData.getManufacturingFee();
                if (Objects.nonNull(manufacturingFee) && Objects.nonNull(manufacturingFee.getDataList())) {
                    List<ManufacturingFeeVo.DataList> subDataList = manufacturingFee.getDataList();
                    List<BydQuotationPrice> list = subDataList.stream().map(sub -> {
                        BydQuotationPrice bydQuotationPrice = new BydQuotationPrice();
                        bydQuotationPrice.setId(IdUtils.simpleUUID());
                        bydQuotationPrice.setMoldSelectionId(moldSelectionId);
                        bydQuotationPrice.setDetailId(bydQuotationDetail.getId());
                        bydQuotationPrice.setType(NormalBYDQuotationaSubEnum.MANUFACTURING.getCn());
                        bydQuotationPrice.setName(sub.getItemName());
                        bydQuotationPrice.setSpecification(null);
                        bydQuotationPrice.setSupplier(BigdecimalUtil.doubleTo2DecimalString(sub.getSupplier()));
                        bydQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                        bydQuotationPrice.setLength(null);
                        bydQuotationPrice.setWidth(null);
                        bydQuotationPrice.setHeight(null);
                        bydQuotationPrice.setNum(BigdecimalUtil.doubleTo1DecimalString(sub.getHour()));
                        bydQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                        return bydQuotationPrice;
                    }).collect(Collectors.toList());
                    bydQuotationPriceList.addAll(list);
                }

                OperatingFeeVo operatingFee = detailData.getOperatingFee();
                if (Objects.nonNull(operatingFee) && Objects.nonNull(operatingFee.getDataList())) {
                    List<OperatingFeeVo.DataList> subDataList = operatingFee.getDataList();
                    List<BydQuotationPrice> list = subDataList.stream().map(sub -> {
                        BydQuotationPrice bydQuotationPrice = new BydQuotationPrice();
                        bydQuotationPrice.setId(IdUtils.simpleUUID());
                        bydQuotationPrice.setMoldSelectionId(moldSelectionId);
                        bydQuotationPrice.setDetailId(bydQuotationDetail.getId());
                        bydQuotationPrice.setType(NormalBYDQuotationaSubEnum.OPERATING.getCn());
                        bydQuotationPrice.setName(sub.getItemName());
                        bydQuotationPrice.setSpecification(null);
                        bydQuotationPrice.setSupplier(null);
                        bydQuotationPrice.setPrice(null);
                        bydQuotationPrice.setLength(null);
                        bydQuotationPrice.setWidth(null);
                        bydQuotationPrice.setHeight(null);
                        bydQuotationPrice.setNum(sub.getDesc());
                        bydQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                        return bydQuotationPrice;
                    }).collect(Collectors.toList());
                    bydQuotationPriceList.addAll(list);
                }

                OtherAccessoriesFeeVo otherAccessoriesFee = detailData.getOtherAccessoriesFee();
                if (Objects.nonNull(otherAccessoriesFee) && Objects.nonNull(otherAccessoriesFee.getDataList())) {
                    List<OtherAccessoriesFeeVo.DataList> subDataList = otherAccessoriesFee.getDataList();
                    List<BydQuotationPrice> list = subDataList.stream().map(sub -> {
                        BydQuotationPrice bydQuotationPrice = new BydQuotationPrice();
                        bydQuotationPrice.setId(IdUtils.simpleUUID());
                        bydQuotationPrice.setMoldSelectionId(moldSelectionId);
                        bydQuotationPrice.setDetailId(bydQuotationDetail.getId());
                        bydQuotationPrice.setType(NormalBYDQuotationaSubEnum.OTHERACCESSORIES.getCn());
                        bydQuotationPrice.setName(sub.getItemName());
                        bydQuotationPrice.setSpecification(sub.getSpecification());
                        bydQuotationPrice.setSupplier(sub.getBrand());
                        bydQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                        bydQuotationPrice.setLength(null);
                        bydQuotationPrice.setWidth(null);
                        bydQuotationPrice.setHeight(null);
                        bydQuotationPrice.setNum(String.valueOf(sub.getCount()));
                        bydQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                        return bydQuotationPrice;
                    }).collect(Collectors.toList());
                    bydQuotationPriceList.addAll(list);
                }

                SteelFeeVo steelFee = detailData.getSteelFee();
                if (Objects.nonNull(steelFee) && Objects.nonNull(steelFee.getDataList())) {
                    List<SteelFeeVo.DataList> subDataList = steelFee.getDataList();
                    List<BydQuotationPrice> list = subDataList.stream().map(sub -> {
                        BydQuotationPrice bydQuotationPrice = new BydQuotationPrice();
                        bydQuotationPrice.setId(IdUtils.simpleUUID());
                        bydQuotationPrice.setMoldSelectionId(moldSelectionId);
                        bydQuotationPrice.setDetailId(bydQuotationDetail.getId());
                        bydQuotationPrice.setType(NormalBYDQuotationaSubEnum.STEEL.getCn());
                        bydQuotationPrice.setName(sub.getItemName());
                        bydQuotationPrice.setSpecification(sub.getSpecification());
                        bydQuotationPrice.setSupplier(BigdecimalUtil.doubleTo3DecimalString(sub.getWeight()));
                        bydQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                        bydQuotationPrice.setLength(String.valueOf(sub.getLength()));
                        bydQuotationPrice.setWidth(String.valueOf(sub.getWidth()));
                        bydQuotationPrice.setHeight(String.valueOf(sub.getHeight()));
                        //当传递 皮纹费用的时候 只有hour 没有 count
                        if (Objects.nonNull(sub.getHour())) {
                            bydQuotationPrice.setNum(String.valueOf(sub.getHour()));
                        } else {
                            bydQuotationPrice.setNum(String.valueOf(sub.getCount()));
                        }
                        bydQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                        return bydQuotationPrice;
                    }).collect(Collectors.toList());
                    bydQuotationPriceList.addAll(list);
                }

                DesignCostVo designCost = detailData.getDesignCost();
                if (Objects.nonNull(designCost) && Objects.nonNull(designCost.getDataList())) {
                    List<DesignCostVo.DataList> subDataList = designCost.getDataList();
                    List<BydQuotationPrice> list = subDataList.stream().map(sub -> {
                        BydQuotationPrice bydQuotationPrice = new BydQuotationPrice();
                        bydQuotationPrice.setId(IdUtils.simpleUUID());
                        bydQuotationPrice.setMoldSelectionId(moldSelectionId);
                        bydQuotationPrice.setDetailId(bydQuotationDetail.getId());
                        bydQuotationPrice.setType(NormalBYDQuotationaSubEnum.DESIGNCOST.getCn());
                        bydQuotationPrice.setName(sub.getItemName());
                        bydQuotationPrice.setSpecification(null);
                        bydQuotationPrice.setSupplier(null);
                        bydQuotationPrice.setLength(null);
                        bydQuotationPrice.setWidth(null);
                        bydQuotationPrice.setHeight(null);
                        bydQuotationPrice.setNum(String.valueOf(sub.getHour()));
                        bydQuotationPrice.setPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getPrice()));
                        bydQuotationPrice.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(sub.getTotalPrice()));
                        return bydQuotationPrice;
                    }).collect(Collectors.toList());
                    bydQuotationPriceList.addAll(list);
                }
            });

            if (Objects.nonNull(bydQuotationDetailList) && !bydQuotationDetailList.isEmpty()) {
                iBydQuotationDetailService.saveBatch(bydQuotationDetailList);
            }
            if (Objects.nonNull(bydQuotationPriceList) && !bydQuotationPriceList.isEmpty()) {
                iBydQuotationPriceService.saveBatch(bydQuotationPriceList);
            }
        } catch (RuntimeException e) {
            log.error("保存比亚迪报价单时失败:{}", e.toString(), e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JSON.toJSONString(R.fail(e.getMessage()));
        } catch (Exception e) {
            log.error("保存比亚迪报价单时失败:{}", e.toString(), e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return JSON.toJSONString(R.fail("保存失败"));
        }
        return JSON.toJSONString(R.success("保存成功"));
    }

    @Override
    public String exportOutQuotation(JSONObject jsonObject, HttpServletResponse res) {
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        if (jsonObject == null || jsonObject.size() < 1) {
            return "{\"msg\":\"参数错误，选模表Id不能为空\",\"code\":400,\"success\":false}";
        }
        String filePath = "";
        //固定值 1 通用  2东风 3  吉利 4 奇瑞 5 BYD
        String mainEnginePlantId = jsonObject.getString("mainEnginePlantId");
        if (mainEnginePlantId.equals("1")) {
            filePath = exportNormalOutQuotationService.exportNormalOutQuotation(this.getNormalOutQuotation(jsonObject));
        }
        if (mainEnginePlantId.equals("2")) {
            filePath = exportDfOutQuotationService.exportNormalOutQuotation(this.getDFOutQuotation(jsonObject), res);
        }
        if (mainEnginePlantId.equals("3")) {
            filePath = exportJlOutQuotationService.exportJlOutQuotation(this.getJLOutQuotation(jsonObject), res);
        }
        if (mainEnginePlantId.equals("4")) {
            filePath = exportQROutQuotationService.exportQROutQuotation(this.getQROutQuotation(jsonObject), res);
        }
        if (mainEnginePlantId.equals("5")) {
            filePath = exportBYDOutQuotationService.exportBYDNewOutQuotation(this.getBYDOutQuotation(jsonObject));
        }
       /* if ("1".equals(moldSelectionId)) {
            return "{\"data\":{\"文件路径 filePath\":\"xxxx/xxx.xlxs\"}}";
        }*/
        return JSON.toJSONString(R.data("文件路径 filePath: " + filePath));
    }

    @Override
    public String getJLOutQuotation(JSONObject jsonObject) {
        if (jsonObject == null || jsonObject.isEmpty()) {
            return JSON.toJSONString(R.fail("参数错误"));
        }
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        //查询奇瑞报价单信息
        LambdaQueryWrapper<JlQuotation> qrQuotationQueryWrapper = new QueryWrapper<JlQuotation>()
                .lambda()
                .eq(JlQuotation::getMoldSelectionId, moldSelectionId);
        JlQuotation jlQuotation = jlQuotationService.getOne(qrQuotationQueryWrapper);
        //初始化
        if (Objects.isNull(jlQuotation)) {
            LambdaQueryWrapper<TestModelParam> testModelParamLambdaQueryWrapper = new QueryWrapper<TestModelParam>()
                    .lambda()
                    .eq(TestModelParam::getMoldSelectionId, moldSelectionId)
                    .orderByAsc(TestModelParam::getMoldId);
            List<TestModelParam> modelParamList = testModelParamService.list(testModelParamLambdaQueryWrapper);
            if (!CollectionUtils.isEmpty(modelParamList)) {
                jlQuotation = new JlQuotation();
                jlQuotation.setId(IdUtils.simpleUUID());
                jlQuotation.setMoldSelectionId(moldSelectionId);
                jlQuotation.setProjectName(modelParamList.get(0).getProjectName());
                jlQuotationService.save(jlQuotation);
                for (TestModelParam testModelParam : modelParamList) {
                    JlQuotationDetail detail = new JlQuotationDetail();
                    detail.setId(IdUtils.simpleUUID());
                    detail.setProductName(testModelParam.getProductName());
                    detail.setProductCode(testModelParam.getProductCode());
                    detail.setMoldSelectionId(moldSelectionId);

                    jlQuotationDetailService.save(detail);

                    //初始化外部分表数据
                    List<JlQuotationPrice> priceList = Arrays.stream(NormalJLQuotationaPriceEnum.values()).map(normalOutQuotationaPriceEnum -> {
                        JlQuotationPrice price = new JlQuotationPrice();
                        price.setId(IdUtils.simpleUUID());
                        price.setDetailId(detail.getId());
                        price.setMoldSelectionId(moldSelectionId);
                        price.setType(normalOutQuotationaPriceEnum.getType());
                        price.setName(normalOutQuotationaPriceEnum.getItemName());
                        price.setPrice(null);
                        price.setLength(null);
                        price.setWidth(null);
                        price.setHeight(null);
                        price.setNum(null);
                        price.setTotalPrice(null);
                        return price;
                    }).collect(Collectors.toList());
                    jlQuotationPriceService.saveBatch(priceList);
                }

            }
        }

        if (Objects.nonNull(jlQuotation)) {
            JlDataVo jlDataVo = new JlDataVo();
            jlDataVo.setZIP(jlQuotation.getZip());
            jlDataVo.setAddress(jlQuotation.getAddress());
            jlDataVo.setContactName(jlQuotation.getContact());
            jlDataVo.setContactPhone(jlQuotation.getPhone());
            jlDataVo.setEMail(jlQuotation.getEmail());
            jlDataVo.setFax(jlQuotation.getFax());
            jlDataVo.setFrom(jlQuotation.getFrom());
            jlDataVo.setMoldSelectionId(jlQuotation.getMoldSelectionId());
            jlDataVo.setProjectName(jlQuotation.getProjectName());
            jlDataVo.setTelphone(jlQuotation.getTel());
            jlDataVo.setTo(jlQuotation.getTo());
            jlDataVo.setUnit(jlQuotation.getUnit());
            jlDataVo.setWebsite(jlQuotation.getWebsite());

            LambdaQueryWrapper<JlQuotationDetail> jlQuotationDetailQueryWrapper = new QueryWrapper<JlQuotationDetail>()
                    .lambda()
                    .eq(JlQuotationDetail::getMoldSelectionId, moldSelectionId)
                    .orderByAsc(JlQuotationDetail::getId);
            List<JlQuotationDetail> list = jlQuotationDetailService.list(jlQuotationDetailQueryWrapper);
            List<JlDetailVo> jlDetailVoList = new ArrayList<>();
            for (JlQuotationDetail jlQuotationDetail : list) {
                JlDetailVo jlDetailVo = new JlDetailVo();
                jlDetailVo.setSubTableId(jlQuotationDetail.getId());
                jlDetailVo.setNameOfProduct(jlQuotationDetail.getProductName());
                jlDetailVo.setCodeOfProduct(jlQuotationDetail.getProductCode());
                jlDetailVo.setPressTon(jlQuotationDetail.getPress());
                jlDetailVo.setProfitFee(StringUtils.isBlank(jlQuotationDetail.getProfit()) ? 0 : Double.valueOf(jlQuotationDetail.getProfit()));
                jlDetailVo.setMouldFee(StringUtils.isBlank(jlQuotationDetail.getMoldTotalFee()) ? 0 : Double.valueOf(jlQuotationDetail.getMoldTotalFee()));
                jlDetailVo.setRemark(jlQuotationDetail.getRemark());
                JlDetailVo jlDetailVoObj = new JlDetailVo();
                BeanUtils.copyProperties(jlDetailVo, jlDetailVoObj);
                //处理吉利原材料
                LambdaQueryWrapper<JlQuotationPrice> rawMaterialQueryWrapper = new QueryWrapper<JlQuotationPrice>()
                        .lambda()
                        .eq(JlQuotationPrice::getMoldSelectionId, moldSelectionId)
                        .eq(JlQuotationPrice::getDetailId, jlQuotationDetail.getId())
                        .eq(JlQuotationPrice::getType, JlQuotationEnum.RAW_MATERIAL.getName())
                        .orderByAsc(JlQuotationPrice::getId);
                List<JlQuotationPrice> rawMaterial = jlQuotationPriceService.list(rawMaterialQueryWrapper);
                List<RawMaterial> rawMaterialJlPriceVoList = new ArrayList<>();
                for (JlQuotationPrice jlQuotationPrice : rawMaterial) {
                    RawMaterial material = new RawMaterial();
                    material.setItemName(jlQuotationPrice.getName());
                    material.setSpecification(jlQuotationPrice.getSpecification());
                    if (null != jlQuotationPrice.getLength()) {
                        material.setLength(StringUtils.isBlank(jlQuotationPrice.getLength()) ? 0 : Double.valueOf(jlQuotationPrice.getLength()));
                    }
                    if (null != jlQuotationPrice.getWidth()) {
                        material.setWidth(StringUtils.isBlank(jlQuotationPrice.getWidth()) ? 0 : Double.valueOf(jlQuotationPrice.getWidth()));
                    }
                    if (null != jlQuotationPrice.getHeight()) {
                        material.setHeight(StringUtils.isBlank(jlQuotationPrice.getHeight()) ? 0 : Double.valueOf(jlQuotationPrice.getHeight()));
                    }
                    if (null != jlQuotationPrice.getNum()) {
                        material.setWeight(StringUtils.isBlank(jlQuotationPrice.getNum()) ? 0 : Double.valueOf(jlQuotationPrice.getNum()));
                    }
                    if (null != jlQuotationPrice.getPrice()) {
                        material.setPrice(StringUtils.isBlank(jlQuotationPrice.getPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getPrice()));
                    }
                    if (null != jlQuotationPrice.getTotalPrice()) {
                        material.setTotalPrice(StringUtils.isBlank(jlQuotationPrice.getTotalPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getTotalPrice()));
                    }
                    rawMaterialJlPriceVoList.add(material);
                }
                JSONObject rawMaterialJsonObj = new JSONObject();
                rawMaterialJsonObj.put("dataList", rawMaterialJlPriceVoList);
                if (StringUtils.isEmpty(jlQuotationDetail.getMaterialFee())) {
                    rawMaterialJsonObj.put("subTotal", 0.0);
                } else {
                    rawMaterialJsonObj.put("subTotal", BigdecimalUtil.stringTo2DecimalDouble(jlQuotationDetail.getMaterialFee()));
                }
                jlDetailVo.setRawMaterial(rawMaterialJsonObj);

                //处理吉利标准件
                LambdaQueryWrapper<JlQuotationPrice> standardComponentQueryWrapper = new QueryWrapper<JlQuotationPrice>()
                        .lambda()
                        .eq(JlQuotationPrice::getMoldSelectionId, moldSelectionId)
                        .eq(JlQuotationPrice::getDetailId, jlQuotationDetail.getId())
                        .eq(JlQuotationPrice::getType, JlQuotationEnum.STANDARD_COMPONENT.getName());
                List<JlQuotationPrice> standardComponent = jlQuotationPriceService.list(standardComponentQueryWrapper);
                List<StandardComponent> standardComponentJlPriceVoList = new ArrayList<>();
                for (JlQuotationPrice jlQuotationPrice : standardComponent) {
                    StandardComponent jlPriceVo = new StandardComponent();
                    jlPriceVo.setItemName(jlQuotationPrice.getName());
                    jlPriceVo.setSpecification(jlQuotationPrice.getSpecification());
                    jlPriceVo.setModelNumber(jlQuotationPrice.getSupplier());
                    if (null != jlQuotationPrice.getNum()) {
                        jlPriceVo.setCount(BigdecimalUtil.stringTo2DecimalDouble(jlQuotationPrice.getNum()));
                    } else {
                        jlPriceVo.setCount(0);
                    }
                    if (null != jlQuotationPrice.getPrice()) {
                        jlPriceVo.setPrice(StringUtils.isBlank(jlQuotationPrice.getPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getPrice()));
                    }
                    if (null != jlQuotationPrice.getTotalPrice()) {
                        jlPriceVo.setTotalPrice(StringUtils.isBlank(jlQuotationPrice.getTotalPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getTotalPrice()));
                    }

                    standardComponentJlPriceVoList.add(jlPriceVo);
                }
                JSONObject standardComponentJsonObj = new JSONObject();
                standardComponentJsonObj.put("dataList", standardComponentJlPriceVoList);
                if (StringUtils.isEmpty(jlQuotationDetail.getStandardComponentFee())) {
                    standardComponentJsonObj.put("subTotal", 0.0);
                } else {
                    standardComponentJsonObj.put("subTotal", BigdecimalUtil.stringTo2DecimalDouble(jlQuotationDetail.getStandardComponentFee()));
                }
                jlDetailVo.setStandardComponent(standardComponentJsonObj);

                //处理吉利人工费
                LambdaQueryWrapper<JlQuotationPrice> artificialFeeQueryWrapper = new QueryWrapper<JlQuotationPrice>()
                        .lambda()
                        .eq(JlQuotationPrice::getMoldSelectionId, moldSelectionId)
                        .eq(JlQuotationPrice::getDetailId, jlQuotationDetail.getId())
                        .eq(JlQuotationPrice::getType, JlQuotationEnum.ARTIFICIAL_FEE.getName());
                List<JlQuotationPrice> artificialFee = jlQuotationPriceService.list(artificialFeeQueryWrapper);
                List<ArtificialFee> artificialFeelPriceVoList = new ArrayList<>();
                for (JlQuotationPrice jlQuotationPrice : artificialFee) {
                    ArtificialFee jlPriceVo = new ArtificialFee();
                    jlPriceVo.setItemName(jlQuotationPrice.getName());
                    if (null != jlQuotationPrice.getNum()) {
                        jlPriceVo.setHour(BigdecimalUtil.stringTo2DecimalDouble(jlQuotationPrice.getNum()));
                    } else {
                        jlPriceVo.setHour(0);
                    }
                    if (null != jlQuotationPrice.getPrice()) {
                        jlPriceVo.setPrice(StringUtils.isBlank(jlQuotationPrice.getPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getPrice()));
                    }
                    if (null != jlQuotationPrice.getTotalPrice()) {
                        jlPriceVo.setTotalPrice(StringUtils.isBlank(jlQuotationPrice.getTotalPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getTotalPrice()));
                    }
                    artificialFeelPriceVoList.add(jlPriceVo);
                }
                JSONObject artificialFeelJsonObj = new JSONObject();
                artificialFeelJsonObj.put("dataList", artificialFeelPriceVoList);
                if (StringUtils.isEmpty(jlQuotationDetail.getArtificialFee())) {
                    artificialFeelJsonObj.put("subTotal", 0.0);
                } else {
                    artificialFeelJsonObj.put("subTotal", BigdecimalUtil.stringTo2DecimalDouble(jlQuotationDetail.getArtificialFee()));
                }


                jlDetailVo.setArtificialFee(artificialFeelJsonObj);

                //处理吉利制造费
                LambdaQueryWrapper<JlQuotationPrice> manufacturingFeeQueryWrapper = new QueryWrapper<JlQuotationPrice>()
                        .lambda()
                        .eq(JlQuotationPrice::getMoldSelectionId, moldSelectionId)
                        .eq(JlQuotationPrice::getDetailId, jlQuotationDetail.getId())
                        .eq(JlQuotationPrice::getType, JlQuotationEnum.MANUFACTURING_FEE.getName());
                List<JlQuotationPrice> manufacturingFee = jlQuotationPriceService.list(manufacturingFeeQueryWrapper);
                List<com.xinchuang.domain.vo.jl.ManufacturingFee> manufacturingFeePriceVoList = new ArrayList<>();
                for (JlQuotationPrice jlQuotationPrice : manufacturingFee) {
                    com.xinchuang.domain.vo.jl.ManufacturingFee jlPriceVo = new com.xinchuang.domain.vo.jl.ManufacturingFee();
                    jlPriceVo.setItemName(jlQuotationPrice.getName());
                    if (null != jlQuotationPrice.getNum()) {
                        jlPriceVo.setHour(BigdecimalUtil.stringTo2DecimalDouble(jlQuotationPrice.getNum()));
                    } else {
                        jlPriceVo.setHour(0);
                    }
                    if (null != jlQuotationPrice.getPrice()) {
                        jlPriceVo.setPrice(StringUtils.isBlank(jlQuotationPrice.getPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getPrice()));
                    }
                    if (null != jlQuotationPrice.getTotalPrice()) {
                        jlPriceVo.setTotalPrice(StringUtils.isBlank(jlQuotationPrice.getTotalPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getTotalPrice()));
                    }
                    manufacturingFeePriceVoList.add(jlPriceVo);
                }
                JSONObject manufacturingFeeJsonObj = new JSONObject();
                manufacturingFeeJsonObj.put("dataList", manufacturingFeePriceVoList);
                if (StringUtils.isEmpty(jlQuotationDetail.getManufacturingFee())) {
                    manufacturingFeeJsonObj.put("subTotal", 0.0);
                } else {
                    manufacturingFeeJsonObj.put("subTotal", BigdecimalUtil.stringTo2DecimalDouble(jlQuotationDetail.getManufacturingFee()));
                }

                jlDetailVo.setManufacturingFee(manufacturingFeeJsonObj);

                //处理吉利装配费
                LambdaQueryWrapper<JlQuotationPrice> assemblyFeeQueryWrapper = new QueryWrapper<JlQuotationPrice>()
                        .lambda()
                        .eq(JlQuotationPrice::getMoldSelectionId, moldSelectionId)
                        .eq(JlQuotationPrice::getDetailId, jlQuotationDetail.getId())
                        .eq(JlQuotationPrice::getType, JlQuotationEnum.ASSEMBLY_FEE.getName());
                List<JlQuotationPrice> assemblyFee = jlQuotationPriceService.list(assemblyFeeQueryWrapper);
                List<com.xinchuang.domain.vo.jl.AssemblyFee> assemblyFeePriceVoList = new ArrayList<>();
                for (JlQuotationPrice jlQuotationPrice : assemblyFee) {
                    com.xinchuang.domain.vo.jl.AssemblyFee jlPriceVo = new com.xinchuang.domain.vo.jl.AssemblyFee();
                    jlPriceVo.setItemName(jlQuotationPrice.getName());
                    if (null != jlQuotationPrice.getNum()) {
                        jlPriceVo.setHour(BigdecimalUtil.stringTo2DecimalDouble(jlQuotationPrice.getNum()));
                    } else {
                        jlPriceVo.setHour(0);
                    }
                    if (null != jlQuotationPrice.getPrice()) {
                        jlPriceVo.setPrice(StringUtils.isBlank(jlQuotationPrice.getPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getPrice()));
                    }
                    if (null != jlQuotationPrice.getTotalPrice()) {
                        jlPriceVo.setTotalPrice(StringUtils.isBlank(jlQuotationPrice.getTotalPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getTotalPrice()));
                    }

                    assemblyFeePriceVoList.add(jlPriceVo);
                }
                JSONObject assemblyFeeJsonObj = new JSONObject();
                assemblyFeeJsonObj.put("dataList", assemblyFeePriceVoList);
                if (StringUtils.isEmpty(jlQuotationDetail.getAssemblyFee())) {
                    assemblyFeeJsonObj.put("subTotal", 0.0);
                } else {
                    assemblyFeeJsonObj.put("subTotal", BigdecimalUtil.stringTo2DecimalDouble(jlQuotationDetail.getAssemblyFee()));
                }
                jlDetailVo.setAssemblyFee(assemblyFeeJsonObj);

                //处理吉利调试费
                LambdaQueryWrapper<JlQuotationPrice> debugFeeQueryWrapper = new QueryWrapper<JlQuotationPrice>()
                        .lambda()
                        .eq(JlQuotationPrice::getMoldSelectionId, moldSelectionId)
                        .eq(JlQuotationPrice::getDetailId, jlQuotationDetail.getId())
                        .eq(JlQuotationPrice::getType, JlQuotationEnum.DEBUG_FEE.getName());
                List<JlQuotationPrice> debugFee = jlQuotationPriceService.list(debugFeeQueryWrapper);
                JSONObject debugFeeJsonObj = new JSONObject();
                for (JlQuotationPrice jlQuotationPrice : debugFee) {
                    JSONObject dataJson = new JSONObject();
                    dataJson.put("price", StringUtils.isBlank(jlQuotationPrice.getPrice()) ? 0.0 : Double.valueOf(jlQuotationPrice.getPrice()));
                    dataJson.put("totalPrice", StringUtils.isBlank(jlQuotationPrice.getTotalPrice()) ? 0.0 : Double.valueOf(jlQuotationPrice.getTotalPrice()));
                    if ("试模".equals(jlQuotationPrice.getName())) {
                        dataJson.put("count", StringUtils.isBlank(jlQuotationPrice.getNum()) ? 0 : Double.valueOf(jlQuotationPrice.getNum()));
                        debugFeeJsonObj.put("tryoutObj", dataJson);
                    } else {
                        dataJson.put("hour", StringUtils.isBlank(jlQuotationPrice.getNum()) ? 0 : Double.valueOf(jlQuotationPrice.getNum()));
                        debugFeeJsonObj.put("debugObj", dataJson);
                    }
                }
                if (StringUtils.isEmpty(jlQuotationDetail.getDebugFee())) {
                    debugFeeJsonObj.put("subTotal", 0.0);
                } else {
                    debugFeeJsonObj.put("subTotal", BigdecimalUtil.stringTo2DecimalDouble(jlQuotationDetail.getDebugFee()));
                }

                jlDetailVo.setDebugFee(debugFeeJsonObj);

                //处理吉利测量费
                LambdaQueryWrapper<JlQuotationPrice> measureFeeQueryWrapper = new QueryWrapper<JlQuotationPrice>()
                        .lambda()
                        .eq(JlQuotationPrice::getMoldSelectionId, moldSelectionId)
                        .eq(JlQuotationPrice::getDetailId, jlQuotationDetail.getId())
                        .eq(JlQuotationPrice::getType, JlQuotationEnum.MEASURE_FEE.getName());
                List<JlQuotationPrice> measureFee = jlQuotationPriceService.list(measureFeeQueryWrapper);
                List<MeasureFee> measureFeePriceVoList = new ArrayList<>();
                for (JlQuotationPrice jlQuotationPrice : measureFee) {
                    MeasureFee jlPriceVo = new MeasureFee();
                    jlPriceVo.setItemName(jlQuotationPrice.getName());
                    if (null != jlQuotationPrice.getNum()) {
                        jlPriceVo.setHour(BigdecimalUtil.stringTo2DecimalDouble(jlQuotationPrice.getNum()));
                    } else {
                        jlPriceVo.setHour(0);
                    }
                    if (null != jlQuotationPrice.getPrice()) {
                        jlPriceVo.setPrice(StringUtils.isBlank(jlQuotationPrice.getPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getPrice()));
                    }
                    if (null != jlQuotationPrice.getTotalPrice()) {
                        jlPriceVo.setTotalPrice(StringUtils.isBlank(jlQuotationPrice.getTotalPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getTotalPrice()));
                    }
                    measureFeePriceVoList.add(jlPriceVo);
                }
                JSONObject measureFeeJsonObj = new JSONObject();
                measureFeeJsonObj.put("dataList", measureFeePriceVoList);
                if (StringUtils.isEmpty(jlQuotationDetail.getMeasureFee())) {
                    measureFeeJsonObj.put("subTotal", 0.0);
                } else {
                    measureFeeJsonObj.put("subTotal", BigdecimalUtil.stringTo2DecimalDouble(jlQuotationDetail.getMeasureFee()));
                }
                jlDetailVo.setMeasureFee(measureFeeJsonObj);

                //处理吉利运输费
                LambdaQueryWrapper<JlQuotationPrice> transportFeeQueryWrapper = new QueryWrapper<JlQuotationPrice>()
                        .lambda()
                        .eq(JlQuotationPrice::getMoldSelectionId, moldSelectionId)
                        .eq(JlQuotationPrice::getDetailId, jlQuotationDetail.getId())
                        .eq(JlQuotationPrice::getType, JlQuotationEnum.TRANSPORT_FEE.getName());
                List<JlQuotationPrice> transportFee = jlQuotationPriceService.list(transportFeeQueryWrapper);
                List<TransportFee> transportFeePriceVoList = new ArrayList<>();
                for (JlQuotationPrice jlQuotationPrice : transportFee) {
                    TransportFee jlPriceVo = new TransportFee();
                    jlPriceVo.setItemName(jlQuotationPrice.getName());
                    if (null != jlQuotationPrice.getNum()) {
                        jlPriceVo.setWeight(StringUtils.isBlank(jlQuotationPrice.getNum()) ? 0 : Double.valueOf(jlQuotationPrice.getNum()));
                    } else {
                        jlPriceVo.setWeight(0);
                    }
                    if (null != jlQuotationPrice.getPrice()) {
                        jlPriceVo.setPrice(StringUtils.isBlank(jlQuotationPrice.getPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getPrice()));
                    }
                    if (null != jlQuotationPrice.getTotalPrice()) {
                        jlPriceVo.setTotalPrice(StringUtils.isBlank(jlQuotationPrice.getTotalPrice()) ? 0 : Double.valueOf(jlQuotationPrice.getTotalPrice()));
                    }
                    transportFeePriceVoList.add(jlPriceVo);
                }
                JSONObject transportFeeJsonObj = new JSONObject();
                transportFeeJsonObj.put("dataList", transportFeePriceVoList);
                if (StringUtils.isEmpty(jlQuotationDetail.getTransportFee())) {
                    transportFeeJsonObj.put("subTotal", 0.0);
                } else {
                    transportFeeJsonObj.put("subTotal", BigdecimalUtil.stringTo2DecimalDouble(jlQuotationDetail.getTransportFee()));
                }
                jlDetailVo.setTransportFee(transportFeeJsonObj);

                JSONObject jsonObj = new JSONObject();
                jsonObj.put("ratio", jlQuotationDetail.getProfitRatio());
                if (StringUtils.isEmpty(jlQuotationDetail.getProfit())) {
                    jsonObj.put("subTotal", 0.0);
                } else {
                    jsonObj.put("subTotal", BigdecimalUtil.stringTo2DecimalDouble(jlQuotationDetail.getProfit()));
                }
                jlDetailVo.setProfitObj(jsonObj);
                jlDetailVoObj.setDetailData(jlDetailVo);
                jlDetailVoList.add(jlDetailVoObj);
            }
            jlDataVo.setDataList(jlDetailVoList);
            return JSON.toJSONString(R.data(jlDataVo), SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullListAsEmpty);

        }

        return JSON.toJSONString(R.fail("无数据"));
    }

    @Override
    public String exportJlQuotation(JSONObject jsonObject, HttpServletResponse response) {
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
     /*   if (
                "1".equals(moldSelectionId)
        ) {
            return "{\"msg\":\"导出成功\",\"code\":200,\"data\":{\"filePath\":\"/xxx/123/123.xlxs\"},\"success\":true}";
        }*/
        if (jsonObject.isEmpty()) {
            return JSON.toJSONString(R.fail("参数错误"));
        }
        String filePath = exportJlOutQuotationService.exportJlOutQuotation(this.getJLOutQuotation(jsonObject), response);
        return JSON.toJSONString(R.data("filePath: " + filePath, "导出成功"));
    }

    @Override
    public String queryInnerMoldPriceByMoldName(JSONObject jsonObject) {
        //jsonobject解析获取模具Id
        String moldId = jsonObject.getString("moldId");
        final List<InnerQuotationDetail> quotationDetails = iInnerQuotationDetailService.list(new LambdaQueryWrapper<InnerQuotationDetail>().like(ObjectUtil.isNotEmpty(moldId), InnerQuotationDetail::getMoldId, moldId));
        final List<InnerBaseInfo> innerBaseInfos = convertInnerQuotation(quotationDetails);
        if (CollectionUtils.isEmpty(innerBaseInfos)) {
            return JSON.toJSONString(R.success("无数据"));
        }
        ReqInnerQuoDetailsVO resp = new ReqInnerQuoDetailsVO();
        resp.setDataList(innerBaseInfos);
//        if (jsonObject == null || jsonObject.size() < 1
//        ){
//            return "{\"data\":{\"dataList\":[{\"detailData\":{\"ironMaterialList\":[{\"totalProcessPrice\":720.0,\"ironMaterialsName\":\"小斜顶\",\"price\":120.0,\"processPrice\":720.0,\"count\":1,\"id\":\"1\",\"materialTotalPrice\":120.0,\"standardComponent\":760.0,\"totalStandardComponentCost\":760.0}],\"gagePrice\":0.0,\"assemblyFeeOfDetail\":{\"totalPrice\":14400.0,\"price\":180.0,\"num\":80},\"moldPartList\":[{\"isRequired\":false,\"partId\":\"1\",\"totalPrice\":0.0,\"manufacturingFee\":0.0,\"isStandardCom\":false,\"partName\":\"A 板\",\"countOfPart\":1,\"isMoldFrame\":false,\"isMainMaterial\":false,\"lengthOfPart\":100.0,\"weightOfPart\":12.0,\"densityOfPart\":0.0000078,\"widthOfPart\":100.0,\"priceOfPart\":0.0,\"heightOfPart\":100.0},{\"isMoldFrame\":true,\"totalPrice\":100.0,\"partId\":\"2\",\"lengthOfPart\":100.0,\"densityOfPart\":0.0000078,\"weightOfPart\":34.0,\"manufacturingFee\":0.0,\"priceOfPart\":100.0,\"widthOfPart\":100.0,\"heightOfPart\":100.0,\"partName\":\"B 板\",\"countOfPart\":1}],\"oilCylinder\":{\"totalPrice\":0.0,\"price\":2500.0,\"num\":0},\"plasticMaterialCost\":{\"totalPrice\":0.0,\"price\":0.0,\"weight\":0.0},\"hotRunner\":{\"totalPrice\":0.0,\"price\":6050.0,\"num\":0},\"transportFeeOfDetail\":27000.0,\"tryoutFeeOfDetail\":{\"hour\":1,\"totalPrice\":450.0,\"price\":450.0,\"deviceId\":\"1688373898296430594\"},\"texturingCost\":{\"area\":0.0,\"totalPrice\":0.0,\"price\":0.0},\"thimblePrice\":27000.0,\"heightOfProduct\":100.0,\"mouldInfo\":{\"heightOfMould\":12.0,\"totalPrice\":120.0,\"price\":12.0,\"widthOfMould\":12.0,\"lengthOfMould\":12.0,\"count\":10.0},\"lengthOfProduct\":200.0,\"graphiteElectrodeCost\":63000.0,\"widthOfProduct\":100.0,\"moldTypeId\":\"1\"}}]}}";
//        }
        return JSON.toJSONString(R.data(resp), SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullListAsEmpty);
    }

}
